feat:增加消息记录功能
This commit is contained in:
26
lib/utils/date_utils.dart
Normal file
26
lib/utils/date_utils.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String formatChatTime(DateTime time) {
|
||||
final now = DateTime.now();
|
||||
final t = time.toLocal();
|
||||
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
final d = DateTime(t.year, t.month, t.day);
|
||||
|
||||
final diff = today.difference(d).inDays;
|
||||
final hm = DateFormat('HH:mm').format(t);
|
||||
|
||||
if (diff == 0) return hm;
|
||||
if (diff == 1) return '昨天 $hm';
|
||||
|
||||
// 本周
|
||||
if (diff < 7 && d.weekday <= now.weekday) {
|
||||
return '${DateFormat('EEEEE', 'zh_CN').format(t)} $hm';
|
||||
}
|
||||
|
||||
if (t.year == now.year) {
|
||||
return DateFormat('M月d日 HH:mm').format(t);
|
||||
}
|
||||
|
||||
return DateFormat('yyyy年M月d日 HH:mm').format(t);
|
||||
}
|
||||
Reference in New Issue
Block a user