- 重命名和更新认证服务中的配置键名 - 在主入口文件中添加时间格式化库的初始化 - 更新设置屏幕中的配置加载和保存逻辑 - 在各个卡片组件中使用时间格式化库显示时间信息
24 lines
770 B
Dart
24 lines
770 B
Dart
class TimeUtils {
|
|
static String getRelativeTime(String timestamp) {
|
|
final now = DateTime.now();
|
|
final date = DateTime.fromMillisecondsSinceEpoch(
|
|
(double.parse(timestamp) * 1000).round(),
|
|
);
|
|
final difference = now.difference(date);
|
|
|
|
if (difference.inSeconds < 60) {
|
|
return '刚刚';
|
|
} else if (difference.inMinutes < 60) {
|
|
return '${difference.inMinutes}分钟前';
|
|
} else if (difference.inHours < 24) {
|
|
return '${difference.inHours}小时前';
|
|
} else if (difference.inDays < 30) {
|
|
return '${difference.inDays}天前';
|
|
} else if (difference.inDays < 365) {
|
|
return '${(difference.inDays / 30).round()}个月前';
|
|
} else {
|
|
return '${(difference.inDays / 365).round()}年前';
|
|
}
|
|
}
|
|
}
|