Flutter 中的日期时间
DateTime in Flutter
我正在为我的应用程序导入国际化,但我在解析我的 String
时遇到问题,但它只 returns 日期而不是时间。当我更改 phone 语言时,我的 Date
格式发生了变化,但我的 Time
没有显示。
这是EN_US
的时候
这是EU(German)
的时候
效果很好,但我的时间格式丢失了...
这是来自 API 的默认字符串:
代码如下:
/// I set a variable that calls the locale of the phone language and changes according to the phone preference
final f = DateFormat.yMd(Localizations.localeOf(context).languageCode);
/// where I dispay time and date but only date is shown in the pictures above
Text('Time and date: ${f.format(DateTime.parse(apicall.dateCreated))}');
我的问题是:如何显示时间以及如何在先显示 Time
然后再显示 Date
之间切换,如果我想先显示 Date
然后再显示 Time
? (例如 18-May-21 11:10h
,如果我想这样做 11:10h 18-May-21
)
在此先感谢您的帮助!
我想你应该使用 DateFormat.jm().add_yMd()
:这将首先显示时间,然后显示日期。要交换它,只需使用 DateFormat.yMd().add_jm()
More info here
我正在为我的应用程序导入国际化,但我在解析我的 String
时遇到问题,但它只 returns 日期而不是时间。当我更改 phone 语言时,我的 Date
格式发生了变化,但我的 Time
没有显示。
这是EN_US
这是EU(German)
效果很好,但我的时间格式丢失了...
这是来自 API 的默认字符串:
代码如下:
/// I set a variable that calls the locale of the phone language and changes according to the phone preference
final f = DateFormat.yMd(Localizations.localeOf(context).languageCode);
/// where I dispay time and date but only date is shown in the pictures above
Text('Time and date: ${f.format(DateTime.parse(apicall.dateCreated))}');
我的问题是:如何显示时间以及如何在先显示 Time
然后再显示 Date
之间切换,如果我想先显示 Date
然后再显示 Time
? (例如 18-May-21 11:10h
,如果我想这样做 11:10h 18-May-21
)
在此先感谢您的帮助!
我想你应该使用 DateFormat.jm().add_yMd()
:这将首先显示时间,然后显示日期。要交换它,只需使用 DateFormat.yMd().add_jm()
More info here