Calculating time for different timezone, problems with daylight savings?

Hi all,
I try to convert my locale time to a different timezone (like a world clock does). This worked until Europe got "summer time". Then my time calculation went wrong. I just paste the following coding to give you a quick reproducable code.
I did a lot of googleing but nothing found so far. Also search here in the forum didn't help me solving it. So now I created a post on my own.
The output of the Java programm is the following (without the colored comments). I just entered these comments to show you where the calculation is right and where it goes wrong.
I have absolutely now idea about where the chase the error. I am only guessing with "daylight savings issue".
Hopefully anybody has a good idea.
Thanks in advance
John
Europe/London {color:#339966} *(correct calculation!)*{color}
daylight shift in millis: 3600000
Is in daylight savings: true
19.04.2010 11:28:53
*Europe/Berlin {color:#339966}(correct calculation){color}*
daylight shift in millis: 3600000
Is in daylight savings: true
19.04.2010 12:28:53
Australia/Sydney{color:#ff0000} (wrong calculation, shoul 1 hour){color}
daylight shift in millis: 3600000
Is in daylight savings: false
*19.04.2010 20:28:53*
America/New_York {color:#339966}(correct calculation){color}
daylight shift in millis: 3600000
Is in daylight savings: true
19.04.2010 06:28:53
Asia/Bangkok {color:#ff0000}(wrong calculation, shoud 1 hour){color}
daylight shift in millis: 0
Is in daylight savings: false
19.04.2010 17:28:53
Asia/Hong_Kong {color:#339966}(correct calculation){color}
daylight shift in millis: 0
Is in daylight savings: false
19.04.2010 18:28:53
package test.timezone;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.LinkedList;
import java.util.List;
import java.util.TimeZone;
public class TZCalc {
public static void main(String[] args) {
List<TimeZone> list = new LinkedList<TimeZone>();
list.add(TimeZone.getTimeZone("Europe/London"));
list.add(TimeZone.getTimeZone("Europe/Berlin"));
list.add(TimeZone.getTimeZone("Australia/Sydney"));
list.add(TimeZone.getTimeZone("America/New_York"));
list.add(TimeZone.getTimeZone("Asia/Bangkok"));
list.add(TimeZone.getTimeZone("Asia/Hong_Kong"));
for (TimeZone tz : list) {
Calendar cal = new GregorianCalendar(tz);
SimpleDateFormat formatter = (SimpleDateFormat) DateFormat
.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
formatter.setTimeZone(tz);
System.out.println("\n"  +tz.getID());
System.out.println("daylight shift in millis: "  tz.getDSTSavings());
System.out.println("Is in daylight savings: "  tz.inDaylightTime(cal.getTime()));
System.out.println(formatter.format(cal.getTime()));
}Edited by: jbegham on Apr 19, 2010 3:46 AM
Edited by: jbegham on Apr 19, 2010 3:47 AM

You should not set the time zone on the calendar since you want the calendar based on UTC.
        List<TimeZone> list = new LinkedList<TimeZone>();
        list.add(TimeZone.getTimeZone("Europe/London"));
        list.add(TimeZone.getTimeZone("Europe/Berlin"));
        list.add(TimeZone.getTimeZone("Australia/Sydney"));
        list.add(TimeZone.getTimeZone("America/New_York"));
        list.add(TimeZone.getTimeZone("Asia/Bangkok"));
        list.add(TimeZone.getTimeZone("Asia/Hong_Kong"));
        Calendar cal = new GregorianCalendar(); // Regardless of your timezone this holds the number of milliseconds since 1/1/1970 UTC.
        for (TimeZone tz : list)
            SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
            formatter.setTimeZone(tz);
            System.out.println("\n" + tz.getID());
            System.out.println("daylight shift in millis: " + tz.getDSTSavings());
            System.out.println("Is in daylight savings: " + tz.inDaylightTime(cal.getTime()));
            System.out.println(formatter.format(cal.getTime()));
        } I have no idea whether or not this then gives the results you expect.

Similar Messages

  • TS3212 I'm runing IE9 & I'm unable to download iTunes.  I receive this error each time: There is a problem with this windows installer package.  A program required for the program to complete could not be found.  Contact your support personnel or package

    I'm running IE 9 & windows 7.  I'm unable to download iTunes.  I receive this error each time: There is a problem with this windows installer package.  A program required for the program to complete could not be found.  Contact your support personnel or package vendor.

    There is a problem with this windows installer package.  A program required for the program to complete could not be found.  Contact your support personnel or package vendor.
    Let's try the following user tip with that one:
    "There is a problem with this Windows Installer package ..." error messages when installing iTunes for Windows

  • Re: Running the same (Forte) application multiple times -for different

    Hi
    We had the same problem - how to deploy a number of identical applications, using each their own db.
    (for training).
    The solution we used is to wrap the entire application into different applications by using a very small
    module called KURSUS01, KURSUS02 etc, that did nothing but call the start procedure of the main app.
    Then in the dbsession connect, we made a call appname to get the application name, and appended the
    first 8 chars to the dbname. Thus our dbnames now points to logicals name: rdbdataKURSUS01, rdbdataKURSUS02 etc.
    All this allows us to deploy the identical apps in the same env, or change one version, and run both the old
    and new program on the same pc and server at the same time (eg. KURSUS01 and KURSUS02).
    I also think this is a kludge - but it works nicely!
    Jens Chr
    KAD/Denmark
    -----Original Message-----
    From: Haben, Dirk <[email protected]>
    To: 'Soapbox Forte Users' <[email protected]>
    Date: 15. januar 1999 09:41
    Subject: Running the same (Forte) application multiple times - for different business clients.
    Hi All
    We have a number of different business clients all willing to use our
    application.
    The (forte) application is to run on our machines etc for these (business)
    clients.
    All (business) clients will have their data kept in separate Oracle DBs
    (instance).
    The problem now is that the entire (forte) application is written using
    DBSessions.
    Now, depending on what business client needs to be serviced (so to speak) we
    need to attach to the right DB - or use the "right" SO.
    The two options we can think of are:
    Option1:
    Programatic change to somehow "know" what (business) client (DB) I'm talking
    about and then use the right DB.
    Pro:
    Only one forte environment to maintain
    Can run multiple (business) clients on same PC at the same time
    Con:
    Requires many program changes
    bending O-O rules(?)
    can't dynamically name SOs so can it be done at all? (ResourceMGRs maybe?)
    Option2:
    Use separate environments! One for each business client.
    Pro:
    More defined separation of app and data,
    SLA-easy
    Con:
    Maintain "n" number of environments
    Can only run the application for one environment (business client) at a time
    on one PC - Big Negative here!
    Not knowing any feasible solution to option 1 (without much code changes and
    developer moaning) I would go for option two; as I have already worked on
    multi-environment setups on VMS back at the Hydro (hi guys).
    I would appreciate any comments from anyone who has solved this problem.
    How, Why Pro Con etc.
    TIA,
    Dirk Haben
    Perth, WA
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Hi
    We had the same problem - how to deploy a number of identical applications, using each their own db.
    (for training).
    The solution we used is to wrap the entire application into different applications by using a very small
    module called KURSUS01, KURSUS02 etc, that did nothing but call the start procedure of the main app.
    Then in the dbsession connect, we made a call appname to get the application name, and appended the
    first 8 chars to the dbname. Thus our dbnames now points to logicals name: rdbdataKURSUS01, rdbdataKURSUS02 etc.
    All this allows us to deploy the identical apps in the same env, or change one version, and run both the old
    and new program on the same pc and server at the same time (eg. KURSUS01 and KURSUS02).
    I also think this is a kludge - but it works nicely!
    Jens Chr
    KAD/Denmark
    -----Original Message-----
    From: Haben, Dirk <[email protected]>
    To: 'Soapbox Forte Users' <[email protected]>
    Date: 15. januar 1999 09:41
    Subject: Running the same (Forte) application multiple times - for different business clients.
    Hi All
    We have a number of different business clients all willing to use our
    application.
    The (forte) application is to run on our machines etc for these (business)
    clients.
    All (business) clients will have their data kept in separate Oracle DBs
    (instance).
    The problem now is that the entire (forte) application is written using
    DBSessions.
    Now, depending on what business client needs to be serviced (so to speak) we
    need to attach to the right DB - or use the "right" SO.
    The two options we can think of are:
    Option1:
    Programatic change to somehow "know" what (business) client (DB) I'm talking
    about and then use the right DB.
    Pro:
    Only one forte environment to maintain
    Can run multiple (business) clients on same PC at the same time
    Con:
    Requires many program changes
    bending O-O rules(?)
    can't dynamically name SOs so can it be done at all? (ResourceMGRs maybe?)
    Option2:
    Use separate environments! One for each business client.
    Pro:
    More defined separation of app and data,
    SLA-easy
    Con:
    Maintain "n" number of environments
    Can only run the application for one environment (business client) at a time
    on one PC - Big Negative here!
    Not knowing any feasible solution to option 1 (without much code changes and
    developer moaning) I would go for option two; as I have already worked on
    multi-environment setups on VMS back at the Hydro (hi guys).
    I would appreciate any comments from anyone who has solved this problem.
    How, Why Pro Con etc.
    TIA,
    Dirk Haben
    Perth, WA
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

  • How to call hr_location_api.create_location for different address style with only those fields that belongs specific to  that address style.

    How to call hr_location_api.create_location for different address style with only those fields that belongs specific to  that address style. It should decide at run time means at run time it will come to know the type of address style and based on that only the fields which belong to address details mapped to calling hr_location_api.create_location.
    Thanks in advance.

    You can create a wrapper package on top of the API (hr_location_api.create_location)
    In the wrapper package you set all the values dynamically based on your requirements(say the style and add_line columns are populated on your conditions) and then you call the API.
    Does that not work ?

  • All Event times change with Daylight Savings time

    With the time change associated with daylight savings time (March 8 2008) all my event times were changed by one hour. EG: events that were 8:45 am are now 7:45 am. I have tried using Time machine to restore to pre March 8 status,but an adjustment takes place and the events remain 1 hour ahead. I have looked through the discussions pages and don't even see the issue identified. I have looked through the menu and preference items and find nothing to help.
    I am surprised not to find this a front page topic today, March 9 2008.
    Can anyone offer some help ?
    Bill Mullen

    Michael,
    I never have changed time zones. Are you suggesting I should have time zone support enabled ?
    I just tried turning on Time Zone Support, then restoring my calendar using Time machine. No change here.
    As I mentioned earlier, this same problem occurred in the fall (although I don't remember which way the event times moved), this time they moved forward. At the Fall change I was using a Mac G4, which I used as a target to build this machine. The only thing I can think of that makes me unique (although I'm not in that small of a group) is that I have altered one of the files in iSync to allow iSync to sync calendar events with iCal. The syncing has always worked OK.
    Right now I'm leary of attempting to do anything with iSync. I'm also finding it difficult to believe I'm not one of 10,000 people experiencing the same problem, but I don't see any other posts.
    I found a time zone in south america which returns my times to the correct figure, with time zone support enabled, but that looks like a deeper hole to dig out of.
    Still stuck,
    Bill

  • How can i get current time in different TimeZone

    Hi alls,
    How can i get current time in different TimeZone.
    I've tried
    final Calendar calendar = Calendar.getInstance(GMT0_TIME_ZONE);
    final Date date = calendar.getTime();
    but it returns current time in my time zone not in GMT0

    a simple way would be:Sometimes gets you the right result (not during daylight saving), but always the wrong way.
    I would strongly recommend getting into the habit of handling Dates correctly. A Date is a universal instant in time - the number of milliseconds since midnight GMT on 1 January 1970. That instant corresponds to various dates and times, depending on your time zone and the effect of daylight saving. You make that conversion of a universal instant to a localized date/time using Calendar and DateFormat.

  • MY phones time did not update with daylights savings. How can I update?

    The time didn't change on my phone with daylight savings. I tried *228 and that didn't fix it. Any other ideas?

    mine DID change. the problem is that i live in AZ and we don't change our clocks. i turned it off and back on and it was back to local time (i didn't have to remove the sim)

  • How to find out the exact time in UK with daylight savings.

    Hi,
    how can i get the exact time in UK even if the daylight savings time is implemented in UK..,
    now my code is implemented for IST ,how can i get the BST timings?
    Thankx.

    the setTimeZone method of SimpleDateFormat (actually inherited from DateFormat). Use it to set it to your timezone when parsing or formatting a date string for your timezone and set it to the UK timezone when parsing or formatting a date string for their timezone.
    Edit: IOW SimpleDateFormat was the answer, not a question.

  • I have continuous problems with my iPad Mini, and it is getting worse!  Newstand application keep pausing or crashing, websites keep hanging first time in but then open fine the second time, and I have problems with applictions crashing.

    I have continuous problems with my iPad Mini, and it is getting worse!  Newstand application keep pausing or crashing, websites keep hanging first time in but then open fine the second time, and I have problems with applictions crashing.  Has anyone experienced similar problems and any suggestions?

    Has the device always behaved this way? Did this start as a result of an update to the iOS software? If the problem is that bad, you should probably restore the iOS software and then restore from a backup. If that fails, restore as new and rebuild the device. If that fails, it's time for a trip to an Apple Store to let them have a look at the iPad.
    Use iTunes to restore your iOS device to factory settings

  • Reminder times change with daylight savings time

    How can I prevent my reminders from changing with daylight savings? I want the times to remain static throughout the year.

    Michael,
    I never have changed time zones. Are you suggesting I should have time zone support enabled ?
    I just tried turning on Time Zone Support, then restoring my calendar using Time machine. No change here.
    As I mentioned earlier, this same problem occurred in the fall (although I don't remember which way the event times moved), this time they moved forward. At the Fall change I was using a Mac G4, which I used as a target to build this machine. The only thing I can think of that makes me unique (although I'm not in that small of a group) is that I have altered one of the files in iSync to allow iSync to sync calendar events with iCal. The syncing has always worked OK.
    Right now I'm leary of attempting to do anything with iSync. I'm also finding it difficult to believe I'm not one of 10,000 people experiencing the same problem, but I don't see any other posts.
    I found a time zone in south america which returns my times to the correct figure, with time zone support enabled, but that looks like a deeper hole to dig out of.
    Still stuck,
    Bill

  • All calendar invites i send say for example 9am, but show 8am by my clients!!! Seems to have started with daylight savings help.

    All calendar invites i send say for example 9am, but show 8am by my clients!!! Seems to have started with daylight savings help. What do i do? change on my MAC settings or icloud?
    Help

    Hi
    Keeepcool,
    I am sorry to tell you that this forum is only covering the C# programming language, IDE, libraries, samples, and tools. Since your issue is not clear to us. I will move your thread to "off-topic " forum. If you have any others issues about C#,
    Please feel free to post in this forum. Thanks for your understading.
    Best Wishes!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Will there be a fix for Firefox's problems with Hotmail. I have gone back to 3.5.9 but mostly I am disappointed by the lack of action on this serious problem where a major and critical feature of a major international website is unavailable in the Firefox

    Will there be a fix for Firefox's problems with Hotmail. I have gone back to 3.5.9 but mostly I am disappointed by the lack of action on this serious problem where a major and critical feature of a major international website is unavailable in the Firefox browser.
    == URL of affected sites ==
    http://www.hotmail.com

    We've reached out to the Hotmail team and they've determined that this is a bug in their code. (It was masked by a timing issue in 3.5 that was fixed in 3.6.) We've worked with them to develop a fix but they may not have deployed it yet.

  • TS1702 I had this Scrabble on my iPad2 and began to have connection problems, it would lock in the "connecting" position. This is not the first time Scrabble has had problems with interface. Typically customers delete the Ap then download it again to rein

    I have contacted EA about this and can find no help. I had this Scrabble on my iPad2 and began to have connection problems, it would lock in the "connecting" position. This is not the first time Scrabble has had problems with interface. Typically customers delete the Ap then download it again to reinstall it. During the process you sign in and approve the purchase KNOWING that another window will open saying that you have previously purchased it and that there is no charge. So what happened this time? It will not connect and all of my saved and current games are wiped out. I want my money back, this game interface is pretty junk and operates like some ancient DOS program,,bug,bug,buggy. I want my money back.

    Go here:
    http://www.apple.com/support/itunes/contact/
    and follow the instructions to report the issue to the iTunes Store.
    Regards.

  • Is there a fix for the WIFI problem with Lion? How can I get Lion off of my Mac?

    Is there a fix for the WIFI problem with Lion? How can I get Lion off of my Mac?

    gmiller0 wrote:
    My mac has 10.7.3 and will not connect to wifi after it wakes up. Have contacted AppleCare but the problem cannot seem to be resolved.. I guess this is a major issue with Lion:(
    What model of Mac?  I have a MBP running 10.7.3 and do not have that issue.  From the other couple of posts I've seen about it, it seems to be maybe an issue with some iMacs?  Have your tried searching the Lion or iMac forums for similar issues, just to see if anyone has hit on why it is happening?

  • After upgrade to ios7, few time i am having problem with my sound/speaker with terroble sound effect like machine or something.but after restart it will be fine.but how this thing can be fix? Because i never had this problem before upgrade to ios7.tq

    After upgrade to ios7, few time i am having problem with my sound/speaker with terroble sound effect like machine or something.but after restart it will be fine.but how this thing can be fix? Because i never had this problem before upgrade to ios7.tq

    Try going into your settings and 'reset all settings'
    You will need to retweak your device but it's been said to help with sound issues.

Maybe you are looking for