• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why is java.util.Date() not displayed correctly?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I am trying to print date and time using java.util.Date() in an expression or scriplet, it is displaying one hour back of system time. However the date is shown correctly. I tried storing it in a date variable and tried incrementing it by 1 to get the correct time but it is throwing an error and unable to increment.

How can I get correct time ?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably a time zone issue.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or given that it is a 1 hour difference, a Daylight time issue.
The rules for daylight time are constantly in flux, and those rules are stored in the Java runtime.
Older Java runtimes may not have up-to-date daylight time rules.

How are you displaying the date?
Just printing out the Date with a toString()?
Using a java.text.DateFormat ?
Using a tag eg JSTL <fmt:formatDate> ?
 
Kv Payal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stefan,

I am using <%= new java.util.Date() %> and it is obviously Daylight savings issue. How to overcome it?

Thanks for answering
 
Ranch Hand
Posts: 144
Oracle Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should really be using the java.util.Calendar interface when dealing with time. The java.util.Date class has been mostly depricated since Java 1.1.
 
Kv Payal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike,

I tried with java.util.Calender and its the same. However I could use the following to get the correct time.

int time=t.get(Calendar.HOUR)+1;

Thanks a lot.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic