Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if date() is monday? java

Tags:

java

date

Is there a way to check if a java Date object is Monday? I see you can with a Calendar object, but date? I'm also using US-eastern date and time if that changes indexing of monday

like image 202
Jake Long Avatar asked Aug 22 '12 19:08

Jake Long


People also ask

How do you check what day of the week is the date Java?

Get the Day of Week using LocalDate (Java 8)now(); DayOfWeek dayOfWeek = today. getDayOfWeek(); System. out. println("Day of the Week :: " + dayOfWeek); System.

What is Calendar Day_of_week in Java?

DayOfWeek is an enum representing the 7 days of the week - Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. In addition to the textual enum name, each day-of-week has an int value. The int value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).

How do you use getDay?

You just need to write the method, getDay, which returns the day on that date. For example, if you are given the date, August 14th 2017, the method should return MONDAY as the day on that date.

How do I know if my LocalDate is Weekend?

Checking a Weekend using LocalDateget(ChronoField. DAY_OF_WEEK) method returns an integer value in the range of 1 to 7. Each integer value represents a different weekday. 1 represents Monday, and so on 6 represents Saturday and 7 represents Sunday.


1 Answers

Something like this will work:

Calendar cal = Calendar.getInstance();
cal.setTime(theDate);
boolean monday = cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY;
like image 91
Dan D. Avatar answered Sep 20 '22 11:09

Dan D.