Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ZONE_OFFSET and DST_OFFSET

 
Rajesh Kumar Hari
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am using Calendar.ZONE_OFFSET and Calendar.DST_OFFSET

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

Thanks
Regards
Rajesh
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic