I'm faced with the issue that I need to convert time from 24 format to AM/PM format (and vice-versa) removing redundant values such as nanoseconds and seconds by time4j library.
I'm using the time4j library because Java can't handle Windows Time Zones and I have to convert them via time4j
Conversion from 24 hour format to AM/PM will depend on users localization. And I want to transmit it (localization) as an argument. Localization will look like "en-US" string.
For example: If users localization is "en-US" then convert 24 hour format to AM/PM. Else keep current value.
Or maybe it's better to get time in the format I need when I already define localization of my user?
Any ideas how to do this? Please help)
I have to spend a lot of time reading time4j doc but my mind is blown
To have full scale of what I'm doing and what the purpose all of this:
I have to get users timeZone from my DB which corresponds to Windows Time Zones and convert them to IANA time zones. I already did this by this method
WindowsZone wzn = WindowsZone.of(userTimeZoneId); //userTimeZoneId="eg. FLE Standart Time"
TZID winZone = wzn.resolveSmart(new Locale("","001"));
System.out.println(winZone.canonical()); // WINDOWS~Europe/Kiev
Where "userTimeZoneId" is timeZone from DB. It corresponds to Microsoft Name of Time Zones
My next step is to get time / or time stamp from users time zone which I already convert to IANA time zones.
I did like this:
PlainTime currentTime = SystemClock.inZonalView(winZone).now().toTime();
//currentTime: "T17:31:37,057"
Where "winZone" converted timeZone (eg. "WINDOWS~Europe/Kiev")
So now returning to my problem I described at the top of the post.
Maybe it's better to get time in the format I need when I already define localization of my user?
How can I convert time from 24 format to AM/PM and vise-versa?
How to remove redundant values such as nanoseconds and seconds?
How can I use user localization in conversion?