我有一个返回 TimeOfDay 对象的时间选择器。但是我必须将该值作为从 DateTime.millisecondsSinceEpoch 获得的毫秒整数保存在数据库中。我怎样才能做到这一点?
最佳答案
这是不可能的。
TimeOfDay
仅保存小时和分钟。而 DateTime
也有日/月/年
如果您想转换它,您将需要更多信息。比如当前的 DateTime。然后将两者合并为一个最终日期时间。
TimeOfDay t;
final now = new DateTime.now();
return new DateTime(now.year, now.month, now.day, t.hour, t.minute);
关于dart - 如何将 flutter TimeOfDay 转换为 DateTime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50198891/