怎么把Flutter TimeOfDay转换成DateTime? [英] How to convert flutter TimeOfDay to DateTime?

查看:207
本文介绍了怎么把Flutter TimeOfDay转换成DateTime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个时间选择器,该选择器返回TimeOfDay对象,但我已将该值保存为一个从DateTime.millisecondsSinceEpoch获得的毫秒数整数。

I have time picker which returns TimeOfDay object but I have save that value in a database as an integer of milliseconds which obtained from DateTime.millisecondsSinceEpoch

推荐答案

这是不可能的。
TimeOfDay 仅保留小时和分钟。尽管 DateTime 还具有日/月/年

This is not possible. TimeOfDay holds only the hour and minute. While a DateTime also has day/month/year

如果要进行转换,则需要更多信息。如当前的DateTime。然后将两者合并为一个最终日期时间。

If you want to convert it, you will need more informations. Such as the current DateTime. And then merge the two into one final datetime.

TimeOfDay t;
final now = new DateTime.now();
return new DateTime(now.year, now.month, now.day, t.hour, t.minute);

这篇关于怎么把Flutter TimeOfDay转换成DateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆