Java DateTimeFormatter不使用阿拉伯语或孟加拉语中的本地数字
我试图使用Java DateTimeFormatter不使用阿拉伯语或孟加拉语中的本地数字,java,android,datetime,kotlin,datetime-format,Java,Android,Datetime,Kotlin,Datetime Format,我试图使用DateTimeFormatterAPI在TextView中显示特定的时间,但每当我运行应用程序时,当我的设备设置为阿拉伯语或孟加拉语时,出于某种原因,时间似乎总是显示西方数字。这是故意的,还是我需要做些什么来解决这个问题 Kotlin class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(sav
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
的实例,即使是本地化的实例,也使用西文/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)输出:
和阿拉伯文(ar):
我希望你能自己翻译我的Java代码。我相信这并不难。将其作为Java本地化数据中的一个bug报告。@OleV.V。在我的代码中,零位数需要在哪里编码?有什么例子吗?
৯:৩০ AM
৫:১৫ PM
٩:٣٠ ص
٥:١٥ م