File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes ZONE_OFFSET and DST_OFFSET Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ZONE_OFFSET and DST_OFFSET" Watch "ZONE_OFFSET and DST_OFFSET" New topic


Rajesh Kumar Hari

Joined: Oct 07, 2008
Posts: 6

I am using Calendar.ZONE_OFFSET and Calendar.DST_OFFSET

Can anyone please tell me the exact use of these in regards of Calendar?

Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

If you look at the Calendar API JavaDoc for these constants, it explains that these values are used as values for the 'field' parameter for the Calendar's set(int field, int value) and get(int field) methods. For example, in the following code, I use the Calendar.ZONE_OFFSET to determine the Greenwich Mean Time (GMT) offset for my computer.

Note that the TimeUnit Enum I use was added in Java 5, and the HOURS was added to that Enum in Java 6. For older versions of Java, you can just do the math yourself.

So basically, these values (along with others in the Calendar class) tell the get and set method what field of the calendar you want the operation to occur on.

In the case of the the GMT offset, I could have done this in a different way:

[ November 11, 2008: Message edited by: Mark Vedder ]
Rajesh Kumar Hari

Joined: Oct 07, 2008
Posts: 6
Thanks Mark..
I agree. Here's the link:
It's not a secret anymore!