티스토리 뷰
현재 프로젝트 진행중 채팅 목록이 필요하여
마지막으로 받은 채팅으로부터 얼마나 지났는지 보여주기 위해 개발이 필요한 상황이다.
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
- NSPrivacyAccessedAPICategoryFileTimestamp
- Xcode
- ITMS-91053: Missing API declaration
- Failed to launch iOS Simulator: Error: Emulator didn't connect within 60 seconds
- NSPrivacyAccessedAPICategoryUserDefaults
- ios 앱 심사상태
- CDN: trunk URL couldn't be downloaded
- PlatformException(sign_in_failed
- 베란다 수경재배
- aws python3.12
- com.google.android.gms.common.api.ApiException: 10:
- NSPrivacyAccessedAPICategorySystemBootTime
- 해결방법
- flutter build ipa
- Firebase
- 아이폰
- Error (Xcode): Target release_unpack_ios failed: Exception: Binary
- 수경재배키트
- ios pod install error
- ios
- Flutter
- python3.12 설치
- MySQL
- EC2
- NSPrivacyAccessedAPICategoryDiskSpace
- google play appcheck
- 슬랙으로 보내기
- Response: Failure when receiving data from the peer
- 리눅스 python3 설치
- but linking in object file
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함