How can I get the names of days of week in JodaTime

user3449772 picture user3449772 · Jun 19, 2014 · Viewed 17.2k times · Source

I've a problem to calculate an entire name list of days of week, using JodaTime. Pratically, I would like to see a similar output based on Locale:

1 day: Sunday 
2 day: Monday 
3 day: Tuesday 
4 day: Wednesday 
5 day: Thursday 
6 day: Friday 
7 day: Saturday

How can I do? I'm new in JodaTime libraries...

Thanks!

Answer

sevensevens picture sevensevens · Jun 19, 2014

Looks like a job for DateTimeFormat

I would start with

 DateTime dt = new DateTime();
 DateTimeFormatter fmt = DateTimeFormat.forPattern("EEEE"); // use 'E' for short abbreviation (Mon, Tues, etc)
 String strEnglish = fmt.print(dt);
 String strFrench = fmt.withLocale(Locale.FRENCH).print(dt);
 String strWhereverUR = fmt.withLocale(Locale.getDefault()).print(dt);

and go from there