【发布时间】:2020-01-30 18:56:20
【问题描述】:
如何从 DART 中的当前时间获取最后 3 小时的时间
我通过这个得到当前时间
DateTime toTime = new DateTime.now();
我想获取最后 30 分钟前的最后 30 分钟,lastOneHour,lastThreeHour,last 6,last 12,last 24 time from the current time.
我试过这样做
from = toTime.subtract(new Duration(hours: 0.5)).millisecondsSinceEpoch;
//This is not working
我正在将这些结果转换为纪元时间。
【问题讨论】:
-
hours 参数是 int 类型,因此不能是浮点值。而是使用分钟参数并将其设置为 30:api.dart.dev/stable/2.5.1/dart-core/Duration/Duration.html