5

在 C# 中,我们有 CultureInfo,它会影响 ToString() 处理日期和数字的方式,例如。您可以通过以下方式设置 CurrentCulture:

Thread.CurrentThread.CurrentCulture = new CultureInfo("pl-PL");;

飞镖中的上述内容是否有任何等价物?

编辑:

  1. 简短的回答是:使用 intl 包(感谢所有人的回答)
  2. 正如 Alan Knight 在下面指出的那样,在 Dart 中“按线程”设置区域设置是没有意义的,因为我们不明确控制线程。
  3. 在我写这个 NumberFormating 的那一刻,据我所知,它正在进行中
4

3 回答 3

3

The intl library will offer you this, although it doesn't affect the behavior of toString().

Here's an example:

Add as a dependency to your pubspec.yaml:

dependencies:
  intl: any # You might specify some version instead of _any_

Then a code sample:

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()));
  });
}

The output looks like this:

07/10/1996 12:08 PM

于 2013-03-31T10:08:41.650 回答
2

是的,根据前面的条目,Intl 库就是您想要的。您可以设置默认语言环境,或使用 withLocale 方法在函数中进行设置。通过线程设置它不起作用,因为没有线程。另一个主要区别是,由于这些都是下载到浏览器中的,因此您不会自动获得所有可用的语言环境数据,而是必须通过异步初始化步骤来加载数据。这可能会很快切换到使用新的延迟加载功能。

此外,语言环境不会影响系统 toString() 操作,但您必须使用 DateFormat 对象来打印日期。由于它仍在进行中,NumberFormat 还不能在语言环境中正常工作,但应该很快。

于 2013-03-30T23:59:09.860 回答
0

http://api.dartlang.org/docs/releases/latest/intl/Intl.html

从页面: Intl 类为国际化相关任务提供了一个公共入口点。

于 2013-03-30T10:58:38.887 回答