티스토리 뷰
현재 프로젝트 진행중 채팅 목록이 필요하여
마지막으로 받은 채팅으로부터 얼마나 지났는지 보여주기 위해 개발이 필요한 상황이다.
formatDate라는 함수를 만들어 date값을 입력받고
현재 시간과 비교하여 현재 시간이 1분 전인 경우 방금 전으로 표시하고
1시간 이전인 경우엔 ~분전
1일 이전인 경우에는 ~시간 전
1일이 지난 경우에는 날짜를 보여주도록 반환하도록 하였다.
String formatDate(DateTime date) {
final now = DateTime.now();
final difference = now.difference(date);
if (difference.inMinutes < 1) {
return '방금 전';
} else if (difference.inHours < 1) {
return '${difference.inMinutes} 분전';
} else if (difference.inDays < 1) {
return '${difference.inHours} 시간 전';
} else {
return '${date.year}.${date.month}.${date.day}';
}
}
'IT > 모바일' 카테고리의 다른 글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- python3.12 설치
- com.google.android.gms.common.api.ApiException: 10:
- NSPrivacyAccessedAPICategorySystemBootTime
- ios pod install error
- 해결방법
- Error (Xcode): Building for 'iOS-simulator'
- but linking in object file
- CDN: trunk URL couldn't be downloaded
- NSPrivacyAccessedAPICategoryUserDefaults
- ios
- google play appcheck
- MySQL
- ITMS-91053: Missing API declaration
- 리눅스 python3 설치
- NSPrivacyAccessedAPICategoryDiskSpace
- Xcode
- EC2
- Firebase
- Error (Xcode): Target release_unpack_ios failed: Exception: Binary
- Failed to launch iOS Simulator: Error: Emulator didn't connect within 60 seconds
- /ios/Pods/MLImage/Frameworks/MLImage.framework/MLImage[arm64][2](GMLImage.o)) built for 'iOS'
- Response: Failure when receiving data from the peer
- 수경재배키트
- NSPrivacyAccessedAPICategoryFileTimestamp
- Flutter
- PlatformException(sign_in_failed
- 베란다 수경재배
- 아이폰
- flutter build ipa
- aws python3.12
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함