From the day week number get the day name with Joda Time

joda-time example
joda-time get day of week
joda datetime tostring
how to get current date in java using joda-time
joda localdate
joda-time instant
java get day of week
java calendar get day of week string

I have a day of the week number: 2 (which should match to Tuesday if week start on Monday).

From this number is there a way to get the name of the day in Java using Joda Time? In javascript it has been quite easy to do it using moment.js:

moment().day(my number)

Joda-Time

At least this works, although I consider it as not so nice:

LocalDate date = new LocalDate();
date = date.withDayOfWeek(2);
System.out.println(DateTimeFormat.forPattern("EEEE").print(date));

Unfortunately Joda-Time does not offer an enum for the day of week (java.time does). I have not quickly found another way in the huge api. Maybe some Joda-experts know a better solution.

Added (thanks to @BasilBourque):

LocalDate date = new LocalDate();
date = date.withDayOfWeek(2);
System.out.println(date.dayOfWeek().getAsText());
java.time

In java.time (JSR 310, Java 8 and later), use the DayOfWeek enum.

int day = 2;
System.out.println( DayOfWeek.of(2).getDisplayName(TextStyle.FULL, Locale.ENGLISH) );
// Output: Tuesday

You can use a particular enum instance directly rather than a magic number like 2. The DayOfWeek enum provides an instance for each day of week such as DayOfWeek.TUESDAY.

System.out.println( DayOfWeek.TUESDAY.getDisplayName(TextStyle.FULL, Locale.ENGLISH) );
// Output: Tuesday
Old JDK

For making it complete, here the solution of old JDK:

int day = 2;
DateFormatSymbols dfs = DateFormatSymbols.getInstance(Locale.ENGLISH);
System.out.println(dfs.getWeekdays()[day % 7 + 1]);

org.joda.time.LocalDate.dayOfWeek java code examples, From the day week number get the day name with Joda Time. LocalDate date = new LocalDate(); date = date.withDayOfWeek(2); System.out.println(date. Joda-Time uses the ISO standard Monday to Sunday week. It does not have the ability to obtain the first day of week, nor to return the day of week index based on any day other than the standard Monday. Finally, weeks are always calculated wrt ISO rules.


You can do it yourself

String[] dayNames = new String[]{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
String name = dayNames[day-1];

And this even does not require any library :)

org.joda.time.LocalDate.withDayOfWeek java code examples, Get first day of a particular week in Joda-Time? java. LocalDate now = new From the day week number get the day name with Joda Time. LocalDate date  org.joda.time.format.DateTimeFormat; time zone names cannot be parsed and a few more symbols are supported. of weekyear number 27 e day of week number 2 E day


Using Joda you can do this:

 DateTime curTime = new DateTime();
 curTime.dayOfWeek().getAsText(Locale.ENGLISH);

Replace Locale with whatever your Locale is.

Should return a week day name such as Monday or Tuesday

Joda-Time – Java date and time API - Formatting, Joda-Time provides a comprehensive formatting system. e day of week number 2 E day of week text Tuesday; Tue y year year 1996 D day of year number 189  Converts this period in weeks to a period in minutes assuming a 7 day week, 24 hour day and 60 minute hour. This method allows you to convert between different types of period. However to achieve this it makes the assumption that all weeks are 7 days long, all days are 24 hours long and all hours are 60 minutes long.


Joda-Time – Java date and time API - User Guide, A period can only be resolved to an exact number of milliseconds by specifying the instant can be used to return the day-of-week name string in French. Converts this period in days to a duration in milliseconds assuming a 24 hour day, 60 minute hour and 60 second minute. This method allows you to convert from a period to a duration. However to achieve this it makes the assumption that all days are 24 hours long, all hours are 60 minutes and all minutes are 60 seconds.


Java date and time API - Fields, These correspond to the common names given to date and time concepts in the The number of milliseconds in the specified time once the day and larger parts are dates are expressed as a day of week, week number and year (week based). Both the GJ and ISO chronologies return 1 for 1BC/BCE, 2 for 2BC/​BCE etc. The Seven-Day Week and the Meanings of the Names of the Days. The Seven Day Week The Naming of the Days Sunday -- Sun's day Monday -- Moon's day Tuesday -- Tiu's day Wednesday -- Woden's day Thursday -- Thor's day Friday -- Freya's day Saturday -- Saturn's day Sources See Also The Seven-Day Week The Babylonians marked time with lunar months.


DateTimeFormat (Joda time 2.2 API), SimpleDateFormat - time zone names cannot be parsed and a few more e day of week number 2 E day of week text Tuesday; Tue y year year 1996 D day of  The Joda-Time design is based around the Chronology. It is a calculation engine that supports the complex rules for a calendar system. It encapsulates the field objects, which are used on demand to split the absolute time instant into recognisable calendar fields like 'day-of-week'. It is effectively a pluggable calendar system.