Does Calendar.getInstance(
) work like a regular singleton in the sense that if I've called getInstance
somewhere else and set the day, month, etc then if I call Calendar.getInstance()
somewhere else those fields will be set to whatever I set them before? In other words, if I want the Calendar.getInstance()
to return a Calendar
object with the current time and day, etc, what do I need to do? Just call clear()
? Does that reset the instance to the current time, etc?
My apologies if this is a stupid question.
Calendar 's getInstance method returns a Calendar object whose calendar fields have been initialized with the current date and time: Calendar rightNow = Calendar.
The getInstance() method in Calendar class is used to get a calendar using the current time zone and locale of the system. Syntax: public static Calendar getInstance() Parameters: The method does not take any parameters. Return Value: The method returns the calendar.
Calendar. getInstance(). getTime() : Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch(January 1, 1970 00:00:00.000 GMT (Gregorian).)
No, Calendar.getInstance()
is not returning a singleton instance. The point of using getInstance()
is that it will take the default locale and time-zone into account when deciding which Calendar implementation to return and how to initialize it.
So you don't need to do anything to get a second Calendar with the current time, just call Calendar.getInstance()
again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With