Timezone in Java calendar

I want to perform operations using a method calendar.getinstance()

. But I am confused that no matter if it's timezone dependent or time dependent.

If it is timezone dependent, please suggest me how to make it timezone independent.

+3


source to share


1 answer


You have four options. From JavaDoc:

  • Calender.getInstance()

    will return a Calender object using the default timezone and locale.
  • Calender.getInstance(TimeZone zone)

    will return a Calendar object using the specified timezone 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 the Calendar object using the specified time zone and locale.


And since the following quote is from the JavaDoc Calendar state, the Calender object always depends on TimeZone. The purpose of the object is to convert between milliseconds since January 1, 1970 00: 00: 00.000 GMT (Gregorian) to YEAR, MONTH, DAY, HOUR, and so on. The later information always depends on the TimeZone.

The Calendar class is an abstract class that provides methods for converting between a specific time in time and a calendar set such as YEAR, MONTH, DAY_OF_MONTH, HOUR, etc., and for manipulating calendar fields, such as getting the date of the next week. A point in time can be represented by a millisecond value this offset from the epoch, January 1, 1970 00: 00: 00.000 GMT (NS).

+2


source







All Articles