Home > Blockchain >  How to get date and time text in arabic format with arabic digits. Android
How to get date and time text in arabic format with arabic digits. Android

Time:01-26

The following code return in english format however I want arabic
currentDate.format(DateFormatter)
currentTime.format(TimeFormatter)

example:
expected: ١٢:٠٠
actual: 12:00

...
        var dateString: String = ""
        var timeString: String = ""
...

        val DateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).withLocale(Locale( "ar"))
        val TimeFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withLocale(Locale( "ar"))

        val currentDate = LocalDate.now()
        val currentTime = LocalTime.now()


        dateString = currentDate.format(DateFormatter)
        timeString = currentTime.format(TimeFormatter)
...

CodePudding user response:

val DateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).withDecimalStyle(DecimalStyle.of(Locale("ar")))
val TimeFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withDecimalStyle(DecimalStyle.of(Locale("ar")))
  •  Tags:  
  • Related