• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Does Java TimeZone takes care of daylight savings?

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi,

In my application i need to show the date corresponding to the timezone of the user. I have written a function which will get Date from database and also users timezone. It then converts the given date to the user`s timezone.

Now iam stuck whether TimeZone takes care of daylight savings or do i need to do some additional stuff for day light savings?
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the API:

TimeZone represents a time zone offset, and also figures out daylight savings.

 
Thanuja Vishwanath
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Day light savings happened from 14-March. I tested my code and found that the day light savings change did not take place and it showed the wrong time.

Iam in India and using IST. i try to convert IST time to CST and it was working fine. I used TimeZone.set and getTimeZone. Now after the day light savings it should work and return the new date and time according to the day light savings. but iam not getting the expected output.

This is my code:



I have set the source time to 8:30 PM IST and the expected output is 10:00 AM CST (as there is a change due to day light savings).
Before day light savings the expected output was 9.00 AM CST(it worked perfect).


In API it is mentioned that TimeZone represents a time zone offset and also figures out daylight savings. So i thought it will take care of daylight savings automatically.

Now iam not getting that day light savings change in time. What should i do for this?

I googled and not able to find a proper solution. My app shows wrong time from today because of day light savings change. Please advise.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What version of Java are you using?

If you are using an older version, it might not have up-to-date information about when daylight savings changes occur. Whenever Oracle releases a new update version of the JDK, the daylight savings information is often updated. Make sure you're using the latest Java update.
 
Thanuja Vishwanath
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote:What version of Java are you using?

If you are using an older version, it might not have up-to-date information about when daylight savings changes occur. Whenever Oracle releases a new update version of the JDK, the daylight savings information is often updated. Make sure you're using the latest Java update.



I was using JDK 5.0 and now I have updated to JDK 1.6.0.24, I am using Netbeans IDE and I have changed the JDK version to 1.6.0.24 in netbeans.conf file. But still the problem remains.

Any clues?

 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried compiling and running your code (using Java 1.6.0_24) and got an exception:

time:8:30 PM(14-Mar)
source:IST
destTz:CST
format:hh:mm a(dd-MMM)
java.text.ParseException: Unparseable date: "8:30 PM(14-Mar)"
at java.text.DateFormat.parse(DateFormat.java:337)
at TimeZoneConversion.convTimeZone(TimeZoneConversion.java:39)
at TimeZoneConversion.main(TimeZoneConversion.java:12)
Exception in thread "main" java.lang.NullPointerException
at java.util.Calendar.setTime(Calendar.java:1075)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:876)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:869)
at java.text.DateFormat.format(DateFormat.java:316)
at TimeZoneConversion.convTimeZone(TimeZoneConversion.java:51)
at TimeZoneConversion.main(TimeZoneConversion.java:12)

The error doesn't seem to have anything to do with time zones, but with a wrong date format. Do you get the same output? Make sure you fix this first.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure that CST is what you want to use? I searched for some info about what CST is exactly and found this:


Time zone offset: UTC - 6 hours
CST is 6 hours behind of Coordinated Universal Time (UTC)

Note that most places observe daylight saving time/summer time during summer, and are therefore using CDT instead in the summer.


It looks like the CST timzone itself doesn't have daylight savings time; the site mentions that specific states switch to CDT in the summer. Maybe you should use a location name like "Europe/Amsterdam" instead of the name of a specific timezone.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajesh Pattabi,
Your post was moved to a new topic.
Please don't put new, unrelated questions at the bottom of an old existing post.
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic