1

I was working on Time conversion from One Locale to another (US to Swedish) in android using Java. It is working well on all the devices except Samsung devices.

DateTimeFormatter parser = DateTimeFormatter.ofPattern("hh:mm a", Locale.US);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm a", new Locale("sv","SE"));
LocalTime time = LocalTime.parse("06:45 AM", parser);
String formatted = time.format(formatter);

In other devices I am getting output as 06:45 FM

In samsung devices I am getting it as 06:45 AM itself.

I want the the output to show as 06:45 FM in every device type.

Note : This issue only occurs for Time conversion,Date conversion (month names) works fine.

Thanks in advance.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Shobhith
  • 505
  • 4
  • 12
  • For context this seems to be a follow-up question to [SimpleDateFormat time conversion from US to Swedish doesn't work on real device but works on emulator](https://stackoverflow.com/questions/74478332/simpledateformat-time-conversion-from-us-to-swedish-doesnt-work-on-real-device). – Ole V.V. Nov 22 '22 at 09:53
  • If your requirements are this precise and strict, I suggest you need to define your `formatter` like this: `new DateTimeFormatterBuilder() .appendPattern("hh:mm ") .appendText(ChronoField.AMPM_OF_DAY, Map.of(0L, "FM", 1L, "EM")) .toFormatter()` (may also pass locale to `toFormatter()` for good measure). – Ole V.V. Nov 22 '22 at 10:01

0 Answers0