check if date() is monday? java

后端 未结 4 549
别跟我提以往
别跟我提以往 2021-02-08 03:34

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 th

4条回答
  •  我寻月下人不归
    2021-02-08 04:04

    You can use Calendar object.

    Set your date to calendar object using setTime(date)

    Example:

    calObj.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
    

    EDIT: As Jon Skeet suggested, you need to set TimeZone to Calendar object to make sure it works perfect for the timezone.

提交回复
热议问题