在 C# 中,我们有 CultureInfo,它会影响 ToString() 处理日期和数字的方式,例如。您可以通过执行以下操作来设置 CurrentCulture:
Thread.CurrentThread.CurrentCulture = new CultureInfo("pl-PL");;
Run Code Online (Sandbox Code Playgroud)
在 dart 中是否有任何等价物?
编辑:
该intl库将为您提供此功能,尽管它不会影响toString().
这是一个例子:
添加为您的依赖项pubspec.yaml:
dependencies:
intl: any # You might specify some version instead of _any_
Run Code Online (Sandbox Code Playgroud)
然后是代码示例:
import 'package:intl/intl.dart';
import 'package:intl/date_symbol_data_local.dart';
main() {
initializeDateFormatting("en_US", null).then((_) {
var formatter = new DateFormat.yMd().add_Hm();
print(formatter.format(new DateTime.now()));
});
}
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
1996年7月10日 12:08 下午
| 归档时间: |
|
| 查看次数: |
1422 次 |
| 最近记录: |