Dart / Flutter如何比较两个TimeOfDay时间? [英] Dart/Flutter How to compare two TimeOfDay times?

查看:1096
本文介绍了Dart / Flutter如何比较两个TimeOfDay时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TimeOfDay 文档没有比较运算符,并且原始比较不起作用。我现在唯一能想到的解决方案是将 TimeOfDay 转换为 DateTime 并使用 DateTime 的差分方法。

TimeOfDay documentation has no comparison operator and primitive comparison does not work. My only solution that I can thinking of right now is to convert TimeOfDay to DateTime and use DateTime's difference method.

有人有更好的解决方案吗?

Does anyone have a better solution?

推荐答案

将其转换为双精度然后进行比较。

Convert it to a double then compare.

double toDouble(TimeOfDay myTime)=> myTime.hour + myTime.minute / 60.0

这篇关于Dart / Flutter如何比较两个TimeOfDay时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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