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.
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.
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).
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));
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);