IT
[Flutter 앱 개발하기] 두 개의 DateTime 변수 차이 구하기
검색일기
2022. 12. 30. 08:35
728x90
두 Datetime 변수 간의 날짜 차이를 구하고 싶다면 아래와 같이 하면 된다.
DateTime now = DateTime.now();
DateTime dt = someTimestampValue.toDate();
if(10 > now.difference(dt).inDays) {
print("Difference is less than 10.");
} else {
print("Difference is more than or equal to 10.");
}
현재 시간 구할 때는 now() 사용하기.
Timestamp 값을 DateTime 값으로 변환할 때는 toDate() 사용하기.
여기서는 사용 안했지만, 문자열로 DateTime 생성할 때는 아래와 같이 parse() 사용하기.
DateTime dt = DateTime.parse("2022-09-23");
728x90