wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Regarding Calendar.HOUR_OF_DAY Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regarding Calendar.HOUR_OF_DAY" Watch "Regarding Calendar.HOUR_OF_DAY" New topic

Regarding Calendar.HOUR_OF_DAY

ravi kanth
Ranch Hand

Joined: Jun 04, 2008
Posts: 36
Hi All,

Can you guys help me to resolve the issue.

in Calendar.HOUR_OF_DAY i am getting 1 hour less than the actual hour.

here is my code.
Calendar grgCal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
Date currentDate = new Date();

calendar.set(Calendar.HOUR_OF_DAY, grgCal.get(Calendar.HOUR_OF_DAY));

int hour = calendar.get(Calendar.HOUR_OF_DAY);

Please help me to figure out the issue.ASAP

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38045
Have you allowed for summer time? It is 12.26 here, but GMT is only 11.26.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

Setting the current time on the calendar is not necessary, because it's already set to the current time by default. Also, I wouldn't explicitly create a GregorianCalendar, but use Calendar.getInstance(); instead:

And this:

This line does nothing at all - it sets the hours of the calendar to the value that it's already set to. What was your intention with this?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Regarding Calendar.HOUR_OF_DAY
Similar Threads
How to compare (Hour) with actual new Date() ?
Time Zone Issue
testing switch() with JUnit
Semantics of the Calendar.set( ... ) methods
Date/Time Retrieval