check if date() is monday? java

后端 未结 4 489
别跟我提以往
别跟我提以往 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:02

    The question doesn't make sense without two extra pieces of information: a time zone and a calendar system.

    A Date object just represents an instant in time. It happens to be Wednesday in the Gregorian calendar in my time zone - but for some folks to the east of me, it's already Thursday. In other calendar systems, there may not even be such a concept of "Monday" etc.

    The calendar system part is probably not a problem, but you will need to work out which time zone you're interested in.

    You can then create a Calendar object and set both the time zone and the instant represented - or, better, you could use Joda Time which is a much better date/time API. You'll still need to think about the same questions, but your code will be clearer.

提交回复
热议问题