DateTimeFormatter 不使用阿拉伯语或孟加拉语的本地数字
DateTimeFormatter not using native numerals in Arabic nor Bengali
我正在尝试使用 DateTimeFormatter
API 来显示 TextView
中的特定时间,但每当我 运行 我的应用程序而我的设备设置为无论是阿拉伯语还是孟加拉语,时间似乎总是出于某种原因显示西方数字。这是故意的,还是我需要做些什么来解决这个问题?
Kotlin
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val localizedTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)
val timeOpen = LocalTime.of(9, 30)
val timeClose = LocalTime.of(17, 15)
tv_time.text = (timeOpen.format(localizedTimeFormatter) +
"\n\n" + timeClose.format(localizedTimeFormatter))
}
}
时钟应用程序(阿拉伯语)
我的应用程序(阿拉伯语)
时钟应用程序(孟加拉语)
我的应用程序(孟加拉语)
这是设计好的。 DateTimeFormatter
的实例,即使是本地化实例,也使用 Western/ASCII 数字,除非另有明确指示。当您知道如何操作时,说明并不难:
DateTimeFormatter localizedTimeFormatter = DateTimeFormatter
.ofLocalizedTime(FormatStyle.SHORT)
.withDecimalStyle(DecimalStyle.ofDefaultLocale());
LocalTime timeOpen = LocalTime.of(9, 30);
LocalTime timeClose = LocalTime.of(17, 15);
String text = timeOpen.format(localizedTimeFormatter)
+ '\n' + timeClose.format(localizedTimeFormatter);
System.out.println(text);
孟加拉语语言环境 (bn-BD) 的输出:
৯:৩০ AM
৫:১৫ PM
阿拉伯语 (ar):
٩:٣٠ ص
٥:١٥ م
我希望你能自己翻译我的 Java 代码。我相信应该不难。
我正在尝试使用 DateTimeFormatter
API 来显示 TextView
中的特定时间,但每当我 运行 我的应用程序而我的设备设置为无论是阿拉伯语还是孟加拉语,时间似乎总是出于某种原因显示西方数字。这是故意的,还是我需要做些什么来解决这个问题?
Kotlin
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val localizedTimeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT)
val timeOpen = LocalTime.of(9, 30)
val timeClose = LocalTime.of(17, 15)
tv_time.text = (timeOpen.format(localizedTimeFormatter) +
"\n\n" + timeClose.format(localizedTimeFormatter))
}
}
时钟应用程序(阿拉伯语)
我的应用程序(阿拉伯语)
时钟应用程序(孟加拉语)
我的应用程序(孟加拉语)
这是设计好的。 DateTimeFormatter
的实例,即使是本地化实例,也使用 Western/ASCII 数字,除非另有明确指示。当您知道如何操作时,说明并不难:
DateTimeFormatter localizedTimeFormatter = DateTimeFormatter
.ofLocalizedTime(FormatStyle.SHORT)
.withDecimalStyle(DecimalStyle.ofDefaultLocale());
LocalTime timeOpen = LocalTime.of(9, 30);
LocalTime timeClose = LocalTime.of(17, 15);
String text = timeOpen.format(localizedTimeFormatter)
+ '\n' + timeClose.format(localizedTimeFormatter);
System.out.println(text);
孟加拉语语言环境 (bn-BD) 的输出:
৯:৩০ AM ৫:১৫ PM
阿拉伯语 (ar):
٩:٣٠ ص ٥:١٥ م
我希望你能自己翻译我的 Java 代码。我相信应该不难。