I have an Event
class. I am using a GregorianCalendar
to store the date of the Event. If I want to find which events have already occurred before today and which events are in the future, does Calendar.getInstance()
give the present date which I can then use to compare?
Yes, you can use Calendar.before()
and Calendar.after()
. Like So:
if(Calendar.getInstance().before(myEvent)){
// do before stuff
} else if(Calendar.getInstance().after(myEvent)) {
// do after
} else {
// do right now
}
Taken off the first search https://www.google.com/search?q=Calendar.getInstance()
Like other locale-sensitive classes, Calendar provides a class method, getInstance, for getting a generally useful object of this type. Calendar's getInstance method returns a Calendar object whose calendar fields have been initialized with the current date and time:
Calendar rightNow = Calendar.getInstance();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.