Dart Date
DateTime
현재 시간 구하기
DateTime Type별 출력
print(now.year);
print(now.month);
print(now.day);
print(now.hour);
print(now.second);
print(now.minute);
print(now.microsecond);
시간 지정하기
DateTime SpecifyDay = DateTime(
int year,
int month,
int day,
int time,
int minutes,
int seconds,
);
간격 구하기
시간 사칙연산
포매팅
문자열을 DateTime으로
예시
void main() {
String nowTime = '2021-10-23 14:00:32';
print(DateTime.parse(nowTime)); // 출력
print(DateTime.parse(nowTime).runtimeType); // DateTime 출력
}
DateTime을 문자열로
포맷 형식대로 DateTime을 포맷해서 문자열로 return 해줌. 포맷 형식은 구글링해보면 많이 나옴.
예시
import 'package:intl/intl.dart';
void main() {
DateTime timeOfBirth = DateTime(2021,12,21,14,30);
DateTime birthDay = DateTime(2021,12,21);
if (birthDay == timeOfBirth) {
print('birthDay and timeOfBirth is a same time'); // 출력 안됨
} else {
print('birthDay and timeOfBirth is not a same time'); // 출력
}
if (DateFormat('yyyy-MM-dd').format(timeOfBirth) == DateFormat('yyyy-MM-dd').format(birthDay)) {
print('DateFormat is working'); // 출력
}
}