获取现在、今天开始、昨天结束、本周开始、本月开始、本年开始的13位时间戳
class TimeUtils {
///获取现在的时间
static int getDayNow(){
var nowTime = DateTime.now();
return nowTime.millisecondsSinceEpoch;
}
///获取今天的开始时间
static int getDayBegin(){
var nowTime = DateTime.now();
var day = new DateTime(nowTime.year, nowTime.month, nowTime.day, 0, 0, 0);
return day.millisecondsSinceEpoch;
}
///获取昨天的开始时间
static int getBeginDayOfYesterday(){
var nowTime = DateTime.now();
var yesterday = nowTime.add(new Duration(days: -1));
var day = new DateTime(yesterday.year, yesterday.month, yesterday.day, 0, 0, 0);
return day.millisecondsSinceEpoch;
}
///获取昨天的结束时间
static int getEndDayOfYesterDay(){
var nowTime = DateTime.now();
var yesterday = nowTime.add(new Duration(days: -1));
var day = new DateTime(yesterday.year, yesterday.month, yesterday.day, 23, 59, 59);
return day.millisecondsSinceEpoch;
}
///获取本周的开始时间
static int getBeginDayOfWeek(){
var nowTime = DateTime.now();
var weekday=nowTime.weekday;
var yesterday = nowTime.add(new Duration(days: -(weekday-1)));
var day = new DateTime(yesterday.year, yesterday.month, yesterday.day, 0, 0, 0);
return day.millisecondsSinceEpoch;
}
///获取本月的开始时间
static int getBeginDayOfMonth(){
var nowTime = DateTime.now();
var day = new DateTime(nowTime.year, nowTime.month, 1, 0, 0, 0);
return day.millisecondsSinceEpoch;
}
///获取本年的开始时间
static int getBeginDayOfYear(){
var nowTime = DateTime.now();
var day = new DateTime(nowTime.year, 1, 1, 0, 0, 0);
return day.millisecondsSinceEpoch;
}
}
网友评论