Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get DateTime dayOfWeek/dayOfMonth as String

Tags:

java

jodatime

How can I get the day of week or month as a String? Without having to do something like:

        DateTime now = DateTime.now();
        String dayOfWeek = null;
        switch(now.getDayOfWeek()) {
            case DateTimeConstants.MONDAY:
                dayOfWeek = "Monday";
                break;
            case DateTimeConstants.TUESDAY:
                dayOfWeek = "Tuesday";
                break;
            case DateTimeConstants.WEDNESDAY:
                dayOfWeek = "Wednesday";
                break;
            case DateTimeConstants.THURSDAY:
                dayOfWeek = "Thursday";
                break;
            case DateTimeConstants.FRIDAY:
                dayOfWeek = "Friday";
                break;
            case DateTimeConstants.SATURDAY:
                dayOfWeek = "Saturday";
                break;
            case DateTimeConstants.SUNDAY:
                dayOfWeek = "Sunday";
                break;
        }
like image 910
LuxuryMode Avatar asked Dec 26 '12 18:12

LuxuryMode


1 Answers

Well, apparently it's just dateTime.dayOfWeek().getAsText(); as documented here.

like image 181
LuxuryMode Avatar answered Oct 30 '22 03:10

LuxuryMode