| 12345678910111213141516171819 |
- class DateRange {
- DateTime startTime;
- DateTime endTime;
- DateRange(this.startTime, this.endTime);
- }
- class TimeUtils {
- //获得离当前最近的时间段
- static DateRange getLastDates(Duration duration) {
- DateTime now = DateTime.now();
- DateTime endTime = DateTime(now.year, now.month, now.day, 23, 59, 59);
- DateTime startTime =
- endTime.subtract(duration).add(const Duration(days: 1));
- startTime =
- DateTime(startTime.year, startTime.month, startTime.day, 0, 0, 0);
- return DateRange(startTime, endTime);
- }
- }
|