80 lines
2.6 KiB
Dart
80 lines
2.6 KiB
Dart
|
|
import 'package:date_format/date_format.dart';
|
|
|
|
class DateTool {
|
|
|
|
String getNowDateYMDHM(){
|
|
// 获取当前时间对象
|
|
DateTime now = DateTime.now();
|
|
|
|
//获取当前时间的年
|
|
int year = now.year;
|
|
//获取当前时间的月
|
|
int month = now.month;
|
|
//获取当前时间的日
|
|
int day = now.day;
|
|
//获取当前时间的时
|
|
int hour = now.hour;
|
|
//获取当前时间的分
|
|
int minute = now.minute;
|
|
//获取当前时间的秒
|
|
int millisecond = now.millisecond;
|
|
|
|
// print("组合 $year-$month-$day $hour:$minute:$millisecond");
|
|
return "$year.$month.$day $hour:$minute";
|
|
}
|
|
|
|
String dateToYMDHNSString(String timeDate){
|
|
int time = int.parse(timeDate);
|
|
DateTime nowDate = DateTime.fromMillisecondsSinceEpoch(time);
|
|
String appointmentDate = formatDate(nowDate, [yyyy,'.',mm,'.',dd,' ',HH,':',nn ,':',ss]);
|
|
return appointmentDate;
|
|
}
|
|
|
|
String dateToYMDHNString(String timeDate){
|
|
int time = int.parse(timeDate);
|
|
DateTime nowDate = DateTime.fromMillisecondsSinceEpoch(time);
|
|
|
|
String appointmentDate = formatDate(nowDate, [yyyy,'-',mm,'-',dd,' ',HH,':',nn]);
|
|
|
|
return appointmentDate;
|
|
}
|
|
|
|
String dateToYMDString(String timeDate){
|
|
int time = int.parse(timeDate);
|
|
DateTime nowDate = DateTime.fromMillisecondsSinceEpoch(time);
|
|
String appointmentDate = formatDate(nowDate, [yyyy,'.',mm,'.',dd]);
|
|
return appointmentDate;
|
|
}
|
|
|
|
String dateToHNString(String timeDate){
|
|
int time = int.parse(timeDate);
|
|
DateTime nowDate = DateTime.fromMillisecondsSinceEpoch(time);
|
|
String appointmentDate = formatDate(nowDate, [HH,':',nn]);
|
|
return appointmentDate;
|
|
}
|
|
|
|
/// 获取是否超过现在的时间
|
|
bool compareTimeIsOvertime(int endTiem){
|
|
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(endTiem); // 将时间戳转换为 DateTime
|
|
DateTime now = DateTime.now(); // 获取当前时间
|
|
if (now.isAfter(dateTime)) {
|
|
print('The timestamp is after the current time.');
|
|
// 过期
|
|
return true;
|
|
} else {
|
|
print('The timestamp is not after the current time.');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// 获取两个距离当前时间相差几天 1705132260000
|
|
int compareTimeGetDaysFromNow(int endTiem){
|
|
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(endTiem); // 将时间戳转换为 DateTime
|
|
DateTime now = DateTime.now(); // 获取当前时间
|
|
Duration difference = dateTime.difference(now); // 计算两个日期之间的差异
|
|
int days = difference.inDays; // 获取差异的天数
|
|
print('dateTime:$dateTime now:$now The difference is $days days.');
|
|
return days;
|
|
}
|
|
} |