• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Kv Payal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably a time zone issue.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Mike Zal
Ranch Hand
Posts: 144
Fedora Java Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!