Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an already existing i18n time unit list in java?

Java disposes of DateFormatSymbols which allows to generate the days of week according to the given locale. Is there the same mecanism for time units (seconds, minutes…) ?

So far, I only found java.util.concurrent.TimeUnit and java.time.temporal.ChronoUnit which dispose of a list in english. but no localized version.

NB : I'm just interested in features from the "vanilla" java7 (I'd rather create my own system than load a full api)

like image 851
merours Avatar asked Oct 31 '22 20:10

merours


1 Answers

In Java 8 there is java.time.temporal.ChronoField#getDisplayName(Locale)

Locale fr = Locale.FRENCH;
System.out.println(ChronoField.HOUR_OF_DAY.getDisplayName(fr));
System.out.println(ChronoField.MINUTE_OF_HOUR.getDisplayName(fr));
System.out.println(ChronoField.SECOND_OF_MINUTE.getDisplayName(fr));

prints

heure
minute
seconde
like image 119
wero Avatar answered Nov 02 '22 10:11

wero