【问题标题】:How to format TimeOfDay to String in flutter如何在颤动中将 TimeOfDay 格式化为字符串
【发布时间】:2020-04-07 21:20:31
【问题描述】:

我想显示当前时间。 使用 TimeOfDay.Now() 获取当前时间,

TimeOfDay _currentTime = TimeOfDay.now();

Text("Current Time: ${_currentTime.toString()}")

使用 Text() 小部件来显示时间,但它显示 TimeOfDay(22.30) 而不是 10.30pm。

如何从 TimeOfDay(22.30) 中删除 TimeOfDay,只想显示 10.30pm。

【问题讨论】:

标签: date flutter dart time formatting


【解决方案1】:

TimeOfDay 对象执行toString 将返回toString 的默认实现,根据文档:

返回此对象的字符串表示形式。

你在这里找的是format吧。

TimeOfDay _currentTime = TimeOfDay.now();
Text("Current Time: ${_currentTime.format(context)}")

还请查看官方文档,以便更好地理解为什么toString 没有达到您的预期。

https://api.flutter.dev/flutter/material/TimeOfDay-class.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 2015-03-26
    • 1970-01-01
    • 2018-10-16
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多