代码之家  ›  专栏  ›  技术社区  ›  wbk727

DateTimeFormatter不使用阿拉伯语或孟加拉语的本地数字

  •  0
  • wbk727  · 技术社区  · 4 年前

    我想用 DateTimeFormatter TextView

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

    时钟应用程序(阿拉伯语)

    enter image description here

    enter image description here

    时钟应用程序(孟加拉语)

    enter image description here

    enter image description here

    0 回复  |  直到 4 年前
        1
  •  1
  •   Anonymous    4 年前

    这是按设计的。实例 DateTimeFormatter

        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):

    ٩:٣٠ ص
    Ù¥:١٥ Ù