-3

Let us suppose we have a date show as.

2015-08-03 12:00:00

How would I convert that to a day's name like Tuesday ? I don't want things like 03 Tue etc. Just the full days name. I looked around but I am bit confused on that.

Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
Theo
  • 3,099
  • 12
  • 53
  • 94
  • 1
    this might help you :>) http://stackoverflow.com/questions/20907809/from-the-day-week-number-get-the-day-name-with-joda-time – Sohail Zahid Aug 03 '15 at 10:08

3 Answers3

1

First, parse that date into a java.util.Date object.

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date yourDate = formatter.parse("2015-08-03 12:00:00");

Then, populate a Calendar with this date:

Calendar c = Calendar.getInstance();
c.setTime(yourDate);
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);

Now you have your day of week dayOfWeek (1 being SUNDAY, for example).

darijan
  • 9,725
  • 25
  • 38
0
 SimpleDateFormat simpleDateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 Date now = simpleDateformat.parse("2015-08-03 12:00:00");
 simpleDateformat = new SimpleDateFormat("EEEE"); // the day of the week spelled out completely
 System.out.println(simpleDateformat.format(now));
Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
  • Please stop editing posts to add code formatting everywhere, it's more distracting than anything else, I already had to modify 2 of your edits to make the posts readable again. Thanks. – 2Dee Aug 03 '15 at 10:30
  • Well , those questions more ugly to have a look before my edit .sorry if i did that.. – Anoop M Maddasseri Aug 03 '15 at 10:40
  • For example, in the question above, you added code formatting to the words *date* and *days*, but that's not code, so it adds incorrect formatting that attracts the eye to unimportant parts of the question. – 2Dee Aug 03 '15 at 10:42
0

This is the solution I came up with:

     SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd  
       HH:mm:ss");
      Date weekDay = null;
      try {
          weekDay = formatter.parse("2015-08-03 12:00:00");
      } catch (ParseException e) {
          e.printStackTrace();
       }
     SimpleDateFormat outFormat = new SimpleDateFormat("EEEE");

     String day = outFormat.format(weekDay);
Bart
  • 19,692
  • 7
  • 68
  • 77
Theo
  • 3,099
  • 12
  • 53
  • 94