dart - 如何将 flutter TimeOfDay 转换为 DateTime?

我有一个返回 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/

相关文章:

flutter - 如何自动将 Flutter 中的图标大小设置为尽可能大

flutter - Builder 与 GlobalKey

android - 如何使用 Android Studio 在 Flutter 中构建 .apk 和

android - Flutter中有WebView吗?

dart - 如何更改或替换 Flutter 中的 ImageCache?

ios - Flutter 应用程序打开,但卡在闪屏上

android - 如何解决 SocketException : Failed host looku

dart - 显示文本字段对话框而不被键盘覆盖?

android - 如何使用 Flutter 处理应用程序生命周期(在 Android 和 iOS

flutter - 如何在 flutter 中使用图像而不是图标?