Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Regarding Calendar.HOUR_OF_DAY

Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Posts: 69881
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you allowed for summer time? It is 12.26 here, but GMT is only 11.26.
Java Cowboy
Posts: 16084
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic