javatimezonemomentjsiana

Java Synchronize Timezone List with moment-timezone.js


I am implementing a setting where the user selects a timezone from a dropdown list, then my app displays the current time in the selected timezone using moment-timezone.js.

I am using TimeZone.getAvailableIDs() to retrieve the list of timezone from the server side to create the dropdown. However, moment-timezone.js is unable to parse some timezone IDs from the list. I checked the size of the list and compared it with moment.tz.names() from moment-timezone.js, and found that the list from moment-timezone.js has about 30 less IDs than the list from Java. I suspect that it may have something to do with the versions of the timezones but I am not sure, as I am using Java 7 and the version I found in ZoneInfoMappings is 2014b, while the data file I have for moment-timezone.js is 2016f.

Is there any way to make both Java and moment-timezone.js retrieve data from the same list so that I can have them synchronized? I am limited to Java 7 and cannot use Time from Java 8, and I prefer to use native Java libraries so I am not considering Joda Time for now.


Solution

  • A few things: