How would I get the current day of the week? Can some please help me?
Asked
Active
Viewed 230 times
-3
-
3Your question is totally incomplete and unclear, the simplest answer is to look in the calendar????? – Buhake Sindi Sep 02 '12 at 15:06
2 Answers
3
Use a Calendar
and get the DAY_OF_WEEK
field:
Calendar cal = Calendar.getInstance();
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
Or if you want the day name instead, you can use SimpleDateFormat
:
Date today = Calendar.getInstance().getTime();
DateFormat df = new SimpleDateFormat("EEEE", Locale.ENGLISH); // override the default Locale
String dayNameInWeek = df.format(today);

João Silva
- 89,303
- 29
- 152
- 158
-
2However, if you want it in words in the correct language for your Locale, look at DateFormatter. – Paul Tomblin Sep 02 '12 at 15:11
0
To get a text display of the day of the week you can use:
DateFormat dateFormat = new SimpleDateFormat("EEEE");
System.out.println("Today is " + dateFormat.format(new Date()));
output:
Today is Sunday

Reimeus
- 158,255
- 15
- 216
- 276