Reputation: 39
I want to perform operations using the calendar.getinstance()
Method. But I am confused that whether it is timezone independent or timezone dependent.
If it is timezone dependent please suggest me to how to make it timezone independent.
Upvotes: 3
Views: 181
Reputation: 704
You have four possiblities. From the JavaDoc:
Calender.getInstance()
will return a Calender-object using the
default time zone and locale. Calender.getInstance(TimeZone zone)
will return a Calendar-object using the specified time zone and
default locale.Calender.getInstance(Locale aLocale)
will return a
Calendar-object using the default time zone and specified locale.Calender.getInstance(TimeZone zone, Locale aLocale)
will return a
Calendar-object using the specified time zone and locale.And as the following quote from the Calendar JavaDoc states, the Calender-object is always TimeZone dependant. The purpose of the object is the transformation between the milliseconds since January 1, 1970 00:00:00.000 GMT (Gregorian) into YEAR, MONTH, DAY, HOUR and so on. The later information is always TimeZone dependant.
The Calendar class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week. An instant in time can be represented by a millisecond value that is an offset from the Epoch, January 1, 1970 00:00:00.000 GMT (Gregorian).
Upvotes: 2