Calculate local time based on timezone offset

I am sure this question has been answered many times. but if you can explain me how to calculate local time based on the timezone offset.
for instance, I am in central time zone. but i want to display local pacific time on my page. I have the timezone offset as -420 minutes.
Thanks in advance.
KM

given a database table tzdata composed of time zone names and tz offset
i want to be able to display the corresponding Date / Time of each country
based on the time zone offset .
in the offsets i posted above i found things like +10.5 ,-1.2 ect..
how to convert those into the correct format so i can feed it to SimpleTimeZone() construtor ?Why would you want to?
I am just pointing out here that java already has all those timezones and offsets configured into it. As well as if/when DST applies.
String[] zones = TimeZone.getAvailableIDs();
        for (int i=0; i<zones.length; i++){
          System.out.println("Zone " + i + " = " + zones[i] + " offset = " + TimeZone.getTimeZone(zones).getRawOffset());
In other words this database table is reinventing the wheel.
You just need to tell Java which Timezone you want (according to the standard names for timezones begin Region/City) and it will work out the correct offset.
eg
for Afghanistan: new TimeZone("Asia/Kabul");
Albania: new TimeZone("Europe/Tirane");
Cheers,
evnafets

Similar Messages

  • Calculate Date/Time based on TimeZone

    Hi guys,
    what i want to do is the following:
    given a database table tzdata composed of time zone names and tz offset
    like this :
    tzName tzOffset summer time used
    Afghanistan ,+4.5, no
    Albania ,+1, yes
    Algeria, +1, yes
    American Samoa,-11, no
    i want to be able to display the corresponding Date / Time of each country based on the time zone offset .
    I'm using a SimpleDateFormat , and want to know how to calulate time for each entry in table above.
    thanks for helping !

    given a database table tzdata composed of time zone names and tz offset
    i want to be able to display the corresponding Date / Time of each country
    based on the time zone offset .
    in the offsets i posted above i found things like +10.5 ,-1.2 ect..
    how to convert those into the correct format so i can feed it to SimpleTimeZone() construtor ?Why would you want to?
    I am just pointing out here that java already has all those timezones and offsets configured into it. As well as if/when DST applies.
    String[] zones = TimeZone.getAvailableIDs();
            for (int i=0; i<zones.length; i++){
              System.out.println("Zone " + i + " = " + zones[i] + " offset = " + TimeZone.getTimeZone(zones).getRawOffset());
    In other words this database table is reinventing the wheel.
    You just need to tell Java which Timezone you want (according to the standard names for timezones begin Region/City) and it will work out the correct offset.
    eg
    for Afghanistan: new TimeZone("Asia/Kabul");
    Albania: new TimeZone("Europe/Tirane");
    Cheers,
    evnafets

  • Error in computing time based on TimeZones on a server

    I have a piece of code that generates timestamps based on US TimeZones such as Pacific, Central and Eastern. I get correct results when I run this code locally (EST) but get results an hour off when I run the same code on a server running in US central time. See the results below and the code that I run.
    Results from running the code on Dev Server:
    ts: 2007-11-05 10:39:03.19 ���� ������� (Default time)
    tsEST: 2007-11-05 10:39:03.019� ������� (EST based on TimeZone String America/New_York, should be 11:39)
    tsCST: 2007-11-05 09:39:03.019� ������� (Central time based on TimeZone String US/Central, should be 10:39)
    tsPST: 2007-11-05 07:39:03.019� ������� (Pacific time based on TimeZone String America/Los_Angeles, should be 8:39)
    Results from running the same code on Local machine:
    tsEST: 2007-11-05 11:39:01.272� (Eastern Time based on TimeZone String America/New_York)
    tsCST: 2007-11-05 10:39:01.272� (Central time based on TimeZone String US/Central)
    tsPST: 2007-11-05 08:39:01.272� (Pacific time based on TimeZone String America/Los_Angeles)
    Below is the code that I ran.
         Timestamp ts = new Timestamp(Calendar.getInstance().getTime().getTime());
    DateFormat df1 = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SS" );
    GregorianCalendar cal1 = new GregorianCalendar();
    Timestamp tsNow = new Timestamp(cal1.getTimeInMillis());
    TimeZone tsEST = TimeZone.getTimeZone("America/New_York");
    String inPattern = "yyyy-MM-dd HH:mm:ss.SS";
    DateFormat df = new SimpleDateFormat(inPattern);
    df.setTimeZone(tsEST);
    Date date = df.parse(tsNow.toString());
    df.setTimeZone(tsEST);
    ts = new Timestamp( df1.parse( df.format(date) ).getTime() );
    System.out.println("tsEST: " + ts.toString());
    DateFormat df2 = new SimpleDateFormat(inPattern);
    TimeZone tsCST = TimeZone.getTimeZone("US/Central");
    df2.setTimeZone(tsCST);
    ts = new Timestamp( df1.parse( df2.format(date) ).getTime() );
    System.out.println("tsCST: " + ts.toString());
    TimeZone tsPST = TimeZone.getTimeZone("America/Los_Angeles");
    df.setTimeZone(tsPST);
    ts = new Timestamp( df1.parse( df.format(date) ).getTime() );
    System.out.println("tsPST: " + ts.toString());

    Actually, I did try a complete removal and re-install with the same results. On the desktop machine on which the Ctime client is working, Ctime was installed on an earlier system version and was working before the upgrade to the current system. The client continued to work. This at least indicates an initial setup problem on 10.2.4 and may indeed relate to the product not yet being ready for the latest system.

  • How to calculate elapsed time based on user input

    I'm not sure what to do next in this program. Basically, I'm not sure exactly how to get the time to output accurately, as in what forumla I should be using.
    This is the question:
    What comes 13 hours after 4 o'clock? Create an ElaspedTimeCalculator application that prompts the user for a starting hour, whether it is am or pm, and the number of elapsed hours. The application then displays the time after that many hours have passed. Application output should look similar to:
    Enter the starting hour: 7
    Enter am or pm: pm
    Enter the number of elapsed hours: 10
    The time is: 5:00 amHere's the code I have so far:
    import java.util.Scanner;
    public class ElapsedTimeCalculator
         public static void main(String[] args)
              int starting_hour;
              int starting_minutes; /*This is added in case the user wants to add minutes as well.*/
              String am_or_pm;
              int elapsed_hours;
              int elasped_minutes;
              int time_hours;
              int time_minutes;
              System.out.println("Welcome. This application will give you the time based on your input.");
              System.out.println(" ");
              Scanner input = new Scanner(System.in);
              System.out.print("Enter the starting hour: ");
              starting_hour = input.nextDouble();
              System.out.print("Enter the starting minutes: ");
              starting_minutes = input.nextDouble();
              System.out.print("Enter either 'am' or pm': ");
              am_or_pm = input.nextString();
              System.out.print("Enter the number of elapsed hours: ");
              elapsed_hours = input.nextDouble();
              input.close();
              time_hours =
              time_minutes = 
              if(am_or_pm = "am" || am_or_pm = "a.m." || am_or_pm = "AM" || am_or_pm = "A.M.")
                   System.out.println("The time is " + time_hours + ":" + time_minutes + "am");
              if(am_or_pm = "pm" || am_or_pm = "p.m." || am_or_pm = "PM" || am_or_pm = "P.M.")
                   System.out.println("The time is " + time_hours + ":" + time_minutes + "pm");
    }To calculate time_hours should I just calculate this by adding the elapsed hour to the starting hour? I doubt it will be accurate for all situations.
    Same for the time_minutes For example, if the starting minutes and the elapsed minutes were 50, it would be greater than 60. Also, not sure if it makes sense to separate hours and minutes like this, it's not required to in the question. I initally thought it would be easier to approach like this instead of allowing the user to input a double for the starting hour. ex. 5.7
    I get the feeling that this is extremely simple, but nonetheless, I'm stuck, so any help would be appreciated.

    Well thanks to both of you. I did a little reading up on the modulus operator and coupled it with some logic (although, truthfully, I'm not really using to there actually being an application for the remainder of a division operation, since it's never really used very much in any of my Math courses) and the hours portion works perfectly now:
    import java.util.Scanner;
    public class ElapsedTimeCalculator
         public static void main(String[] args)
              int starting_hour;
              //int starting_minutes; /*This is added in case the user wants to add minutes as well.*/
              String am_or_pm;
              int elapsed_hours;
              //int elasped_minutes;
              System.out.println("Welcome. This application will give you the time based on your input.");
              System.out.println(" ");
              Scanner input = new Scanner(System.in);
              System.out.print("Enter the starting hour: ");
              starting_hour = input.nextInt();
              //System.out.print("Enter the starting minutes: ");
              //starting_minutes = input.nextInt();
              System.out.print("Enter either 'am' or pm': ");
              am_or_pm = input.next();
              System.out.print("Enter the number of elapsed hours: ");
              elapsed_hours = input.nextInt();
              input.close();
              int time_hours = 0;
              //int time_minutes;
              String meridien;
              if(am_or_pm.equals("am"))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("am"))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("AM"))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("A.M."))
                   time_hours = (starting_hour + elapsed_hours) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("pm"))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("p.m."))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("PM"))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              else if(am_or_pm.equals("P.M."))
                   time_hours = (starting_hour + elapsed_hours + 12) % 24;
                   //time_minutes = (starting_minutes + elapsed_minutes) % 60;
              if(time_hours < 12)
                   meridien = "A.M.";
                   System.out.println("The time is: " + time_hours + ":00 " + meridien);
              else if(time_hours > 12)
                   meridien = "P.M.";
                   System.out.println("The time is: " + time_hours + ":00 " + meridien);
    }Now the only thing is the minutes. My teacher did say she wants the user to have the option to input minutes also if he/she desires, so I do need it. However, the only problem is that if say the user inputs a "starting minute" of 14 for example, and 66 minutes elapsing, then (14 + 66) int/ 60 = 1r20 but using the modulus operator would only give me 20. So how will I be able to add any extra hours if it is necessary?

  • How to change timezone in B2B to reflect date fields per local time in DB

    Hi,
    I am in EST zone and I could see the data in database with date columns having time in PST. One of my transaction just errorred , I could see from B2B user interface tool error report message date time as 2:14 EST, while when I check the database values from TOAD the value is 11:14, which indicates there is some setup which might have caused to update Pacific Time in the database, I am not sure what could be the setup. Can anyone please indicate or provide inputs on what could be the cause and how to set up the application so that the date type data is updated with local time in database.
    Thanks
    Sachin Sutar

    Hi Sachin,
    We store the message using the database time. It seems like the database time zone is set to PST. To change it to a different time zone, please follow the instructions on this link:
    http://www.oracle.com/technology/products/oracle9i/daily/may02.html
    Hope this helps,
    Eng

  • Timezone offset for dst in LabVIEW 8.5

    I think there is a "bug" in LabVIEW 8.5.1 and probably 8.5 too. I used to have an application that was transmitting timestamp data between computers in some sort of HTTP protocol. The server application has been build in LabVIEW 7.1 and remains in that version for various reasons.
    Now the timestamps are transmitted as UTC formatted strings according to RFC1123. In order to do that I used an old function developed in LabVIEW 6.x or so that calculates the current timezone offset from a timestamp value of 86400 seconds (eg. Jan 2, 1904, 12:00:00 AM GMT). Turning that into a date time rec I observed the actual day, hours and minutes to calculate the timezone offset.
    With LabVIEW 7.1 the timestamps in LabVIEW started to use the actual timezone offset valid for the timestamp except if that timestamp was earlier than 1970 in which case it still used the current timezone offset as it did before.
    LabVIEW 8.5(.1) apparently changed that behaviour to always use the timezone offset of the actual timestamp and since 2 Jan 1904 was probably in every country (at least on the northern hemisphere) non-DST it now gives a different timezone offset than it used to do since the beginning of LabVIEW 2.5. This is cause me an hour or two of debugging :-(.
    Of course the new >= 8.0 solution to calculate the timezone offset is now to convert a current timestamp into a non-UTC date time rec and convert that date time rec back into a timestamp telling it that it is a UTC record and then subtract the original timestamp from that.
    I would expect the Internet Toolkit to have that same problem unless it has been adapted for LabVIEW 8.5, since my original routine was at some point "loaned" from that toolkit.
    Rolf Kalbermatter                            
    Message Edited by rolfk on 06-13-2008 02:59 PM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

    jimfoxy wrote:
    I had a similar problem. I thought it was an intentional feature.
    I frequently work with GMT date & timestamped data as an int/double number of seconds or hours. Is there a sensible philosophy of displaying such data on a graph (with X-axis selected as 'Absolute time') without having to first convert the times into system timezone-dependent numbers? What I am doing at the moment is reading the GMT data in, converting it into timezone dependent values to display and manipulate (by applying the method above), then converting the results back again in order to output correct GMT to various files.
    I always find it hard to work with time in Labview because you need to keep a close eye on local system timezone settings, unless you ensure that you set the PC's clock to GMT non-daylight savings (not an option for me). It is great that there is now an on/off UTC option for some of the time related VIs.
    I don't want to mess around with timestamp datatype because I need to perform manipulation such as division and can't get that to work with timestamps.
    Thanks.
    It is not a LabVIEW problem really but simply a problem of any application running on a localized date/time system. And since time in any other form than SI normalized is a ratherbeasty thing, it gets troublesome to deal with it in software.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Datetime of Records UTC vs. Local Time

    Hi, I notice that the Integrator automatically converts the datetime of records to UTC upon insertion. In Studio however, we want the analysis / records to reflect our local time instead. The Endeca Server Data Loading Guide http://docs.oracle.com/cd/E37502_01/server.751/es_data_loading/toc.htm#dateTime%20property mentions about the possibility of updating a record with two datetime properties. How is this achieved using Integrator? My records seem to be converted automatically into UTC even when I append the timezone. Thanks!

    I'm afraid this explanation doesn't quite address the question... but it's close.
    The real question is what "based on UTC time" means, vs. "UTC time"
    Assume your SCCM server is set to deploy the update at 8PM UTC, but Windows time on your SCCM server (due to the time zone it is in) is configured for UTC-2, which is 6PM when "true" UTC is at 8PM.  When does the update happen?  8PM (true
    UTC time), or 6PM (SCCM server time "based on" UTC", which includes the offset)?  I understand that all target servers will deploy simultaneously (since we selected UTC instead of local), but is that simultaneous time "true" UTC,
    or the SCCM server UTC +/- offset?

  • Timezone Offset to timezone conversion

    Hi ,
    I have timezone offset +6:00 which is coming from xml.
    how to get time zone from it.

    This looks very wrong. Java Date objects ALWAYS store the date as the number of milliseconds since 1st Jan 1970 UTC. They have no timezone component other than that implied by the UTC.
    Your method public static Date toGMTDate(Date date1, TimeZone tz1)implies that you can create a Date with a Timezone other than UTC. You can't.
    The only time a Timezone is involved is when you convert the Date to a String for display and then the Timezone is that specified in SimpleDateFormat or the local timezone if one is not not specified.

  • 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.

  • Finding out timezone from TimeZone offset

    Hi,
    I'm using JavaScript to find out the local time on client, setting it to a cookie.
    I then retrieve the value in a JSP page to find out the correction necessary for adjusting the time (in UTC) to local time. The problem, however, is that JavaScript returns the Daylight Savings Offset and the Zone_offset as one total, making it impossible to find out what TimeZone this Offset maps to.
    My utility class is using the myCalendarObj.setTimeZone (tz) to adjust the time stamp.
    Any suggestions on how I could find out what TimeZone my offset maps to, or any other suggestion??
    Regards,
    Mark

    And what to do with problem of Daylight Saving Time? Not all countries use it. For instance, try to get all TimeZone IDs for GMT +00:00...
    For this moment, I see only 2 solution: write a little applet, that will be detect TimeZone of client or lets user to detect his location (like in "Settings" for this page - top right corner). But it's bad solutions.

  • Free Oracle Driver gives GMT as if it were local time

    I am using v.9.2.0 of ojdbc14.jar.
    The client machine (where the JDBC driver is used) is set to Eastern Standard Time (EST).
    So that machine is 5 hours behind GMT.
    The database machine is set to PST.
    So that machine is 8 hours behind GMT.
    Via JDBC I send the following query from the client machine:
    select current_timestamp from dual
    I then perform:
    Timestamp ts = rs.getTimestamp(1);
    At 4:41pm EST (local machine time where the JDBC driver code is running), the following 2 lines of code:
    System.out.println("***" +ts);
    System.out.println("***" +ts.toGMTString());
    Gives the following 2 lines of output:
    ***2003-02-05 21:41:00.579
    ***6 Feb 2003 02:41:00 GMT
    The first line of output shows 9:41 pm EST.
    But that is not correct.
    It seems that the JDBC driver is lying to me...
    taking a GMT value and saying that it is EST (local time).
    I'm thinking that is the only way that the 2nd line of output would be what it is.
    The same problem also occurs when using i-Net's Oranxo driver for JDBC 3.0.
    Am I missing something here, or doing something wrong ?
    My JDBC code later feeds this incorrect value back to the driver to update a column in the database.
    Has anyone seen this problem before and gotten past it ?
    Currently, the only ways I see to get around it are:
    1. be able to figure out the database offset (difference between system time on the database machine and GMT), from my JDBC code so that I can make the adjustment in my code.
    OR
    2. be able to tell the database "this is GMT" when I give it a timestamp value to insert or update.
    Thanks for any help.
    Matt McGinty

    Hi Matt,
    Yes, I have encountered problems similar to the ones you are describing. I found that the cause was due to the fact that the JRE classes have "rules" regarding daylight savings time -- and try to adjust dates and times according to these "rules".
    What I did was to configure the default time zone so that it had no daylight savings times rules. This solved my problems.
    Using JDK 1.4.1_01, I run the following code -- on starting up the JVM -- that "initializes" the default time zone:
    [Please excuse the poor formatting of the below code -- I haven't figured out how to format code properly when posting to this forum, yet.]
    TimeZone l_defaultTimeZone = TimeZone.getDefault();
    int l_rawOffset = l_defaultTimeZone.getRawOffset();
    String l_id = l_defaultTimeZone.getID();
    SimpleTimeZone l_simpleTimeZone = new SimpleTimeZone(
    l_rawOffset,
    l_id,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0);
    TimeZone.setDefault(l_simpleTimeZone);
    Hope this helps you.
    Good Luck,
    Avi.

  • Converting UTC dates to local time

    Hello all. I have some data I imported that has a date column containing dates spanning a number of years. The dates are in the UTC timezone.
    I need to display the dates in the local time zone that was in effect at the time. I've seen many fine examples of converting from one time zone to another. But I need it to be smarter than that. For example, date/times (this year) prior to 03/09/2008 2AM should display in EST (my zone in effect then), while date/times on/after then should display in EDT.
    Are there any Oracle built-in functions to do this, or will I need to gather the data of when daylight savings time begins/ends for the years I have dates and write my own function? I don't need help for the latter; I just don't want to reinvent the wheel. Also, I don't want to convert the data; I append to it regularly.
    Thanks for your help and consideration.

    Sergiusz, thanks again. When I added a very recent date, I saw the effect. But perhaps something is wrong with my local 10gR1 "play" database. It seems the DST start point is not correct. Should it not start showing -4 offset at row# 4? I didn't see a change until I added the last date. But I believe DST began on 3/9/2008 at 2am local, which is 7am UTC.
    ~Pete
    SQL> DROP   TABLE imported_events;
    Table dropped.
    SQL> CREATE TABLE imported_events (event_date TIMESTAMP(0) WITH TIME ZONE);
    Table created.
    SQL> BEGIN
      2  INSERT INTO  imported_events VALUES ( '10-JAN-08 2:00:00 PM UTC');
      3  INSERT INTO  imported_events VALUES ( '08-MAR-08 2:00:00 PM UTC');
      4  INSERT INTO  imported_events VALUES ( '09-MAR-08 6:59:00 AM UTC');
      5  INSERT INTO  imported_events VALUES ( '09-MAR-08 7:01:00 AM UTC');
      6  INSERT INTO  imported_events VALUES ( '09-MAR-08 2:00:00 PM UTC');
      7  INSERT INTO  imported_events VALUES ( '10-MAR-08 2:00:00 PM UTC');
      8  INSERT INTO  imported_events VALUES ( '09-JUN-08 2:00:00 PM UTC');
      9  COMMIT;
    10  END;
    11  /
    PL/SQL procedure successfully completed.
    SQL> COLUMN ROWNUM         FORMAT 99
    SQL> COLUMN event_date_utc FORMAT A25
    SQL> COLUMN offset_local   FORMAT 99
    SQL> COLUMN offset_eastern FORMAT 99
    SQL> SELECT ROWNUM
      2        ,event_date event_date_utc
      3        ,TO_CHAR(CAST((event_date AT LOCAL) AS DATE),'YYYY-MM-DD HH24:MI:SS') date_local
      4        ,(CAST((event_date AT LOCAL) AS DATE) - CAST(event_date AS DATE))*24 offset_local
      5        ,TO_CHAR(CAST((event_date AT TIME ZONE 'US/Eastern') AS DATE),'YYYY-MM-DD HH24:MI:SS') date_eastern
      6        ,(CAST((event_date AT TIME ZONE 'US/Eastern') AS DATE) - CAST(event_date AS DATE))*24 offset_eastern
      7    FROM imported_events
      8   ORDER BY 1;
    ROWNUM EVENT_DATE_UTC            DATE_LOCAL          OFFSET_LOCAL DATE_EASTERN        OFFSET_EASTERN
         1 10-JAN-08 02.00.00 PM UTC 2008-01-10 10:00:00           -4 2008-01-10 09:00:00             -5
         2 08-MAR-08 02.00.00 PM UTC 2008-03-08 10:00:00           -4 2008-03-08 09:00:00             -5
         3 09-MAR-08 06.59.00 AM UTC 2008-03-09 02:59:00           -4 2008-03-09 01:59:00             -5
         4 09-MAR-08 07.01.00 AM UTC 2008-03-09 03:01:00           -4 2008-03-09 02:01:00             -5
         5 09-MAR-08 02.00.00 PM UTC 2008-03-09 10:00:00           -4 2008-03-09 09:00:00             -5
         6 10-MAR-08 02.00.00 PM UTC 2008-03-10 10:00:00           -4 2008-03-10 09:00:00             -5
         7 09-JUN-08 02.00.00 PM UTC 2008-06-09 10:00:00           -4 2008-06-09 10:00:00             -4
    7 rows selected.
    SQL>

  • Conversion between local time and UTC: Anomaly at Daylight saving time edge

    Hi all,
    I want to convert back and forth between local time including all peculiarities like DST etc. This is the core of my code:
        Date d=new Date(toEpoch());
        Calendar cal=Calendar.getInstance(tz);
        cal.setTime(d);
        int offs=(cal.get( Calendar.ZONE_OFFSET )+cal.get( Calendar.DST_OFFSET ));
        System.out.println("zone_offset: "+cal.get( Calendar.ZONE_OFFSET )+", dst_offset: "+cal.get( Calendar.DST_OFFSET )+", offset: "+offs);
        Calendar cal2=Calendar.getInstance(TimeZone.getTimeZone("Etc/UTC"));
        System.out.println(cal2.getTimeZone().getID());
        cal2.setTime(d);
        cal2.add(Calendar.MILLISECOND,-offs);
        d=cal2.getTime();Looks (and, actually, is) rather complicated. I take two different calendar objects to be absolutely sure that no accidental DST conversion hits me on the UTC side.
    The general case works as expected:
    Date (fourteen digits, 'x'=Exit): 20050909190000
    Entered date: Fr, 9.9.2005, 19:00
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Etc/UTC
    Date in UTC:  Fr, 9.9.2005, 17:00I live in timezone Europe/Berlin, so during DST we have GMT+2. Let's see what's happening on christmas (non-DST):
    Date (fourteen digits, 'x'=Exit): 20051224180000
    Entered date: Sa, 24.12.2005, 18:00
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Etc/UTC
    Date in UTC:  Sa, 24.12.2005, 17:00As expected!
    Now, we enter the dark zone of DST: Each year DST is turned on and off and it seems as if this leads to problems in both cases. Let's start with the next event of this case: At Oct., 30th, 2005, DST is turned off between 2:00 and 3:00 at night. So, we have once 2:30 with DST and (one hour later) 2:30 again without DST. Java, however, garbles things completely (I'm leaving the unneeded lines of my debug output out now):
    Entered date: So, 30.10.2005, 01:59
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  Sa, 29.10.2005, 23:59
    Entered date: So, 30.10.2005, 02:00
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Date in UTC:  So, 30.10.2005, 02:00
    Entered date: So, 30.10.2005, 02:30
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Date in UTC:  So, 30.10.2005, 02:30
    Entered date: So, 30.10.2005, 02:59
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Date in UTC:  So, 30.10.2005, 02:59
    Entered date: So, 30.10.2005, 03:00
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Date in UTC:  So, 30.10.2005, 02:00So, directly before the DST change, offset is computed correctly. From 3:00 onward, also. But in between, Calendar does neither take an offset of two hours (what would be somehow correct) nor one hour (also somehow correct). Even though it predicts to take the one-hour zone offset into consideration, "GMT" time is actually the same as local time.
    Things become even wireder at the other edge of the DST time range: This year, DST began on March, 27th, 2005: Let's see what is happening:
    Entered date: So, 27.3.2005, 01:59
    zone_offset: 3600000, dst_offset: 0, offset: 3600000
    Date in UTC:  So, 27.3.2005, 00:59
    Entered date: So, 27.3.2005, 02:00
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 00:00
    Entered date: So, 27.3.2005, 02:30
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 00:30
    Entered date: So, 27.3.2005, 02:59
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 00:59
    Entered date: So, 27.3.2005, 03:00
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 00:00
    Entered date: So, 27.3.2005, 04:59
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 01:59
    Entered date: So, 27.3.2005, 05:00
    zone_offset: 3600000, dst_offset: 3600000, offset: 7200000
    Date in UTC:  So, 27.3.2005, 03:00While at 1:59, everything is ok, 2:00 is handled as within DST. That's ok, as the hour between 2:00 and 3:00 did not exist in that night in our local time zone, but at 3:00 the system totally screws up things as it suddenly subtracts three hours (while pretending to use two hours). This goes on until 5:00 in the morning when time is shown correctly again.
    Can anyone help me? What am I doing wrong? How do I actually convert correctly between a DST-aware local time zone and GMT/UTC?
    Best regards,
    Dirk

    Well, I would not say I did "just about everything" wrong. Actually, Calendar is not GMT-only as it has time zone information and converts its internal time according to that information if I use the getTime() function (what I do).
    In my applications, I handle dates in my own data structures. My EDate object (which is part of the QJCC library hosted on SourceForge) stores years, months, days, minutes, hours, and seconds seperately. Using this class, I managed to get an actually working time zone conversion this way:
      public void toUTC(TimeZone tz) {
        Calendar cal=Calendar.getInstance(tz);
        cal.clear();
        cal.set(year,month-1,day,hour,minute,second);
        int offs=(cal.get( Calendar.ZONE_OFFSET )+cal.get( Calendar.DST_OFFSET ));
        //System.out.println("zone offset: "+cal.get( Calendar.ZONE_OFFSET )+", DST offset: "+cal.get( Calendar.DST_OFFSET ));
        second-=(offs/1000);
        normalize();
    normalize() does something similar to the lenient stuff in Calendar.
    I will now write the method for the other direction. The most interesting item will be the answer to the question:
    "Tell me the correct DST_OFFSET in TimeZone X when I have the actual point of time given in UTC."
    Perhaps someone can give me a hint?!?

  • Timedatectl local time is five hours behind my real wall clock time?

    timedatectl will look like this
    Local time: Thu-2015-02-19 14:00:00 EST
    Universal time: Thu-2015-02-19 19:00:00 UTC
    RTC Time: Thu-2015-02-19 19:00:00
    My universal and rtc is the right time and my local time is incorrect. How can I make them all 19:00:00? I tried reading the time wiki and searched for various articles and I'm still confused.

    Based on the timestamp of when you posted this, it looks like your UTC and RTC are off by 5 hours.  THAT is the problem.
    As an example, I'm in the same timezone as you:
    $ timedatectl
    Local time: Wed 2015-02-18 19:43:06 EST
    Universal time: Thu 2015-02-19 00:43:06 UTC
    RTC time: Thu 2015-02-19 00:43:05
    Time zone: US/Eastern (EST, -0500)
    Please read: https://wiki.archlinux.org/index.php/Time

  • Getting difference between GMT time and Local time

    Folks,
    I am trying to get difference between gmt time and local time for Korea time zone.
    which should be 9 hours.
    Instead of 9, I am getting 15 hours diff.
    What am I doing wrong?
    Here's what I did to test it:
    First I set the system (Windows XP) time zone to Soul (Korea GMT+9hours) time zone.
    Then I ran the following program, and I got 15 hour diff, not 9.
    Thank you in advance!
    import java.util.*;
    public class Using_GregorianCalendar
         public static void main(String args[])
              Using_GregorianCalendar ugc = new Using_GregorianCalendar();
              ugc.getTimeDiff();
         public void getTimeDiff()
              Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
              Calendar cal1 = new GregorianCalendar(cal.get(Calendar.YEAR),
                                           cal.get(Calendar.MONTH),
                                           cal.get(Calendar.DATE),
                                           cal.get(Calendar.HOUR_OF_DAY),
                                           cal.get(Calendar.MINUTE),
                                                      cal.get(Calendar.SECOND));
            int gmtHour          =  cal.get(Calendar.HOUR); //(Calendar.HOUR_OF_DAY);
            int gmtHourOfDay =  cal.get(Calendar.HOUR_OF_DAY);
            int gmtMonth        =  cal.get(Calendar.MONTH);
            int gmtYear          =  cal.get(Calendar.YEAR);
            int gmtMinute       =  cal.get(Calendar.MINUTE);
            int gmtSecond     =   cal.get(Calendar.SECOND);
            int gmtDate         = cal.get(Calendar.DATE);
            Calendar localCal  = Calendar.getInstance();
            int localHourOfDay = localCal.get(Calendar.HOUR_OF_DAY);
            int timeDiff = (localHourOfDay - gmtHourOfDay);
              //Korea time is GMT + 9 hours so I should get a difference of 9
              //why am I getting difference of 15?
                 System.out.println("************** in getTimeDiff() **********************");
              System.out.println("gmtDate: "+gmtDate);
              System.out.println("gmtHour: "+gmtHour);
              System.out.println("gmtHourOfDay: "+gmtHourOfDay);
              System.out.println("localHourOfDay: "+localHourOfDay);
              System.out.println("timeDiff: "+timeDiff);
              System.out.println("**********************************************************");
         }//getTimeDiff()
    }//class Using_GregorianCalendar
    /*              here's the output of this program:
         ************** in getTimeInGMT() **********************
         gmtDate: 14
         gmtHour: 6
         gmtHourOfDay: 18
         localHourOfDay: 3
         timeDiff: -15
    */

    DrClap wrote:
    sabre150 wrote:
    Nearly correct since the Daylight saving may or may not be in effect which does depend on the date...I would simplify that to this:
    TimeZone korea = TimeZone.getTimeZone("Asia/Seoul");
    long delta = korea.getOffset(new Date().getTime());
    System.out.println(delta / (1000.0 * 60 * 60));That's assuming that the OP really meant UTC when he/she said "GMT". Most people don't realize there's a distinction and that Java's timezones are all based relative to UTC.I suspect you are right in assuming that the OP want UTC and not GMT. I figured it was better to illustrate that the method can be used for getting the time difference between any two TimeZones.

Maybe you are looking for

  • Reason for rejection for sale order stock existing line item

    Hi,     I am giving reason for rejection for a line item where there is already sale order stock. Then I am getting a warning message like " there is sale order stock assigned". I want this message to be as error message. Any customisation (SPRO) is

  • Sudden Loss of Power... but computer works fine...

    I've had my dual 1.8 for about three years now... it's not in the category of G5's that had the power recall. I have it hooked to a Belkin UPS backup, but for the last week or so, the computer will abruptly lose power. I haven't installed any new app

  • Partition

    I have a table that has telephone number and subscriber details. Subscriber_table subscriber_id tel_no (e.g 416 888 224) address pin This is a massive table having millions of records.The table is indexed on tel_no ,yet when a search is made on telep

  • Write to excel

    i created a VI that would open excel, write to a sheet then save as original_timestamp (this way i had a clean template each time), the problem i ran into was i opened the original each time so everytime i wrote to new sheet only the most recent shee

  • MBP+WinXP won't connect to network. It sees the wireless network but stops.

    I've been fighting this for two solid days. Time Capsule takes an address automatically from my router/modem. The MacBook Pro connects wirelessly thru Time Capsule to my ethernet network and the internet. No problems. Windows XP on the same Mac wirel