Reputation: 9
I have a Calendar object as below where I get the value as below
Calendar qrExpiryDate =
java.util.GregorianCalendar[time=1651237080000,areFieldsSet=true,areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id="GMT-04:00",offset=-14400000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2022,MONTH=3,WEEK_OF_YEAR=18,WEEK_OF_MONTH=5,DAY_OF_MONTH=29,DAY_OF_YEAR=119,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=5,AM_PM=0,HOUR=8,HOUR_OF_DAY=8,MINUTE=58,SECOND=0,MILLISECOND=0,ZONE_OFFSET=-14400000,DST_OFFSET=0]
I would like to check if this date is expired or not, by doing a validation using java with the current date. How can I achieve this?
Upvotes: 0
Views: 345
Reputation: 1760
If you must use the Calendar object, you could do something like like
new Date().before(calendar.getTime());
or
calendar.getTime().after(new Date());
However, the Date()
class is mostly deprecated. You should use LocalDateTime
or ZonedDateTime
Upvotes: 1