Date in words in java

How do I display the date in words in Java?

Example:

11 09 2018-eleventh of September two thousand and eighteenth year

Author: default locale, 2018-05-03

2 answers

In a good way, of course, you need to write a descendant class DateFormat in which you need to implement the translation from numbers to writing. The task is frankly not easy...

However, not everything is so bad, for quick-fix, you can use the libu tradukisto, which can translate more or less any number Integer into a script in a multilingual version. Roughly speaking, it is necessary to decompose the date into 3 numbers: date, month and year and run each of them through the appropriate method, such as:

int day=22;
int month=11;
int year=2019;
ValueConverters converter = ValueConverters.RUSSIAN_INTEGER;
String dayAsWords = converter.asWords(new Integer(day));
String monthAsWords = converter.asWords(new Integer(month));
String yearAsWords = converter.asWords(new Integer(year));

System.out.println(dayAsWords+" "+monthAsWords+" "+yearAsWords);
 2
Author: Barmaley, 2019-11-22 08:32:43

There is no such pattern in Java, you will have to replace the numbers with words yourself, unfortunately. For example, break the date into the components

Day month year, and make a string of them

 0
Author: Vyacheslav Gusser, 2018-05-07 15:08:50