How get current time zone offset ?

Hi,
I am facing to a problem related getting time zone offset.
Below code is used for my application :
NSDate* sourceDate = [NSDate date];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
timeZoneOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate] / 3600;
But sometimes seems that above code is getting work wrong. For example :
Knoxville, TN : time zone offset should be -5. But my code resulted it as -4.
http://www.timeanddate.com/worldclock/city.html?n=843
This web is related my issue. Here is :
Standard time zone: UTC/GMT -5 hours
Daylight saving time: +1 hour
Current time zone offset: UTC/GMT -4 hours
Actually I don't know how get to "Daylight saving time:".
Can you correct this issue for me ?
Please advice.
Thanks.

Hi Raiden -
RaidenMAC wrote:
Knoxville, TN : time zone offset should be -5. But my code resulted it as -4.
I think your code is giving you the correct offset for Knoxville on today's date. The offset for Eastern Standard Time (EST) is -5, but Knoxville is currently on Eastern Daylight Time (EDT), which is one hour later than EST. (-5) + 1 => (-4), which is what your code computed.
Note that [secondsFromGMTForDate:|http://developer.apple.com/library/ios/documentation/Co coa/Reference/Foundation/Classes/NSTimeZoneClass/Reference/Reference.html#//appleref/doc/uid/20000190-CACDIAIC] is correcting for daylight savings time. That's why you need to pass the date to that method. If you pass a "summer" date, the return offset will be one hour more than it will be for a "winter" date (usually early November to mid March). For example, try moving the date forward 60 days like this:
NSDate *sourceDate = [NSDate dateWithTimeIntervalSinceNow:3600 * 24 * 60];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
int timeZoneOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate] / 3600;
NSLog(@"sourceDate=%@ timeZoneOffset=%d", sourceDate, timeZoneOffset);
The above should give you the offset for Knoxville on Dec. 7, 2010, which is a winter date.
Actually I don't know how get to "Daylight saving time:".
You can test a NSTimeZone object with [isDaylightSavingTimeForDate:|http://developer.apple.com/library/ios/documentat ion/Cocoa/Reference/Foundation/Classes/NSTimeZoneClass/Reference/Reference.html#//appleref/doc/uid/20000190-CHDCJGHE], but you don't need that information when you obtain the offset with secondsFromGMTForDate:.
- Ray

Similar Messages

  • How to remove time zone offset when we use a number as a relative time variable?

    Hi everyone!
    I've a small doubt in using a number as a relative time. If I change the display properties of a numeric to relative time, it takes default value "5:30 AM", may be because I'd set time zone to Indian time during installation ( India is 5:30 hours ahead of Greenwhich). I want it to take default value "12:00 AM'. Please help me how I do it?
    ( I can also subtract 5:30 hours and get the same. But I want that to have "12:00 AM" by default......?!)
    Thank you all..!
    pavamana

    pavamana_pk wrote:
    Hi everyone!
    I've a small doubt in using a number as a relative time. If I change the display properties of a numeric to relative time, it takes default value "5:30 AM"
    As Ravens already stated, you are using ABSOLUTE time.  Relative time can only be set to display hours, minutes, and/or seconds.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How can i get current time of a given timezone

    how can i get current time of a given timezone
    for example: Asia/Hong_Kong
    my code is like this, but the result is not correct.
    what's wrong?
    import java.util.*;
    public class test {
    public static void main(String[] args){
              String s = "Asia/Hong_Kong";
              String tempS = "";
              TimeZone myTime = new SimpleTimeZone(s);
              //TimeZone myTime = TimeZone.getTimeZone(s);
              Calendar myCal = new GregorianCalendar(myTime);
              tempS = myCal.get(Calendar.YEAR)+"-"+
                        (myCal.get(Calendar.MONTH)+"-"+
                        myCal.get(Calendar.DATE)+" "+
                        (myCal.get(Calendar.HOUR)+":"+
                        myCal.get(Calendar.MINUTE)+":"+
                        myCal.get(Calendar.SECOND);
              System.out.println(tempS);
    output is : 2001-7-15 11:16:48
    but the correct time should be: 2001-8-16 7:17:48
    the correct time should be 2001-8-16

    Certain indexes in the Calendar API start at 0 rather then 1, so, when you get the value, you may want to increment.
    I'm not sure why the time is incorrect. You may want to call getAvailableIDs() and make sure that the desired TimeZone ID is supported by your version. I doubt that Sun would have incorrect support for the time zone, but it may not be included, or perhaps it is included with a diffrent ID. You can always create your own time zone as well, by passing the String offset to getTimeZone(), the offset being how many hours beyond or before GMT. Hopefully this helps.

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

  • How to get current time and date??

    How to get current time and date from my PC time and date to the java application??
    i use java.util.* package but got error, that is:
    - java.util.* and java.sql.* class are match
    - abstract class cannot be instantiated
    so what can i do, pls guide...thanks...

    There is a method in the System class that will return the current system time. You could also instantiate a Date, Time, Timestamp, or Calendar object, all of which get created with the system time by default.
    Don't import *. Import the specific classes you need.
    Next time, post the actual text of the exceptions/compile errors. If you make people guess, most just won't bother.

  • How can we get current time date with resultset?

    Dear All,
    I have to insert current time date in the table.So,i need to get the current time and date with result set.So,I will first get the time date and then insert it into the table.
    I know how can we get current time and date without resultset.i have created this function its working.But now i want to use this.mean using resultset i want to put in the table.
    How can i do this?
    public static String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
    public static String now() {
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
    return sdf.format(cal.getTime());
    }

    yuck. Why not simply set a "new java.sql.Date()" to the SQL parameter in question?

  • How to get Machine time zone in Powerbuilder?

    Do we have any way to get machine time zone in Powerbuilder script?
    Thanks in advance.

    Hello,
    Use the GetTimeZoneInformation API:
    FUNCTION ulong GetTimeZoneInformation(ref str_timezoneinformation str) LIBRARY "Kernel32.dll" alias for "GetTimeZoneInformation"
    Obviously, you need to create the structure argument of type str_timezoneinformation
    For your convenience, below the exported structure:
    global type str_time_zone_information from structure
    long bias
    string standardname
    str_systemtime standarddate
    long standardbias
    string daylightname
    str_systemtime daylightdate
    long daylightbias
    end type
    global type str_systemtime from structure
    unsignedinteger wYear
    unsignedinteger wMonth
    unsignedinteger wDayOfWeek
    unsignedinteger wDay
    unsignedinteger wHour
    unsignedinteger wMinute
    unsignedinteger wSecond
    unsignedinteger wMilliseconds
    end typ
    See GetTimeZoneInformation function (Windows)
    HTH,
    Jacob

  • Time Zone Offset - Date Format question

    I'm wondering if any one knows how to display the time zone offset of a date in the following format "[+-]HH:mm." More so... I need the date/time in the ISO 8601 format "yyyy-MM-dd'T'HH:mm:ss[+-]HH:mm", where the last [+-]HH:mm is the hour representation of the offset. Here's some sample code...
    SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Calendar rightnow= Calendar.getInstance();
    // So if system date/time is February 14, 2002 at 1:15:00 PM EST, this would produce "2002-02-14T13:15:00"
    System.out.println("Current Datetime" + sdf1.format rightnow.getTime());
    How can I get the timezone offset appended to my output in a [+-]HH:mm format. So, the above date needs to look like "2002-02-14T13:15:00-05:00". I can get the offset in milliseconds by doing the following:
    int offset1 = rightnow.get(rightnow.ZONE_OFFSET) + rightnow.get(rightnow.DST_OFFSET);
    But how can you get this representation into the [+-]HH:mm format?
    thanks in advance,
    stophman

    Try something like this:import java.text.* ;
    import java.util.* ;
    static public String formatISO8601(Calendar cal) {
         * create ISO 8601 formatter for Calendar objects
        MessageFormat iso8601 = new MessageFormat("{0,time}{1,number,+00;-00}:{2,number,00}") ;
        // need to shove a date formatter that is cognizant of the
        // calendar's time zone into the message formatter
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") ;
        df.setTimeZone(cal.getTimeZone()) ;
        iso8601.setFormat(0, df) ;
         * calculate the time zone offset from UTC in hours and minutes at the current time
        long zoneOff = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET) ;
        zoneOff /= 60000L ;  // in minutes
        int zoneHrs = (int) (zoneOff / 60L) ;
        int zoneMins = (int) (zoneOff % 60L) ;
        if (zoneMins < 0) zoneMins = -zoneMins ;
        return (iso8601.format(new Object[] {
                                    cal.getTime(),
                                    new Integer(zoneHrs),
                                    new Integer(zoneMins)
    }

  • How change 'home' time-zone in ical?

    Hi
    Question ... how to change 'home' time-zone in ical?
    I have just relocated countries ... to a different time zone.
    I use time-zone support in iCal and add time-zone to various tasks.
    But when i add a task and note it as my now current time-zone then ical immediately alters the diary placement to assume that i am in my old country/time-zone.
    I have altered the region in Preferences/International but this seems to have no effect, in ical at least.
    guidance welcomed
    ross

    In the very upper, right-hand corner of the iCal window is a time zone display, here you can choose to change your iCal time zone.
    If you choose "other" from the time zone display's pop-up menu, you get a dialog just like the Date and Time System Preferences.
    Why this option is not in the iCal preferences, I have no idea. To me, that would make a lot more sense!
    -Doug

  • Retrieve System Time Zone Offset?

    Hi, I'm doing some GPS emulation and need to retrieve the system Time Zone Offset in (Hour and Minute). For example if Mountain time zone offset hour = -7 and Minute = 00. Is this information possible to get in Labview?
    Thanks.

    Hello QRP,
    Yes, it can be done, but this way is not very elegant. It will get the GMT offset that your PC has as its current setting.
    Use Format Date/TIme String with a format string of "%z". The output is the offset as a STRING formatted HH:MMS
    Break the string apart with Scan From String to get the individual elements, or by using "%t" as the format, get the offset in seconds.
    Rod.
    EDIT: There shouldn't be a smiley in the time format above, It's "HH : MM : SS" but ignore the spaces!

  • How to handle time zones?

    I'm trying to use some external data in Numbers and I'm having trouble.  First, there was the iso-8601 issue, (I don't see functions for converting to/from).
    Second, once I've converted them, (using a combo of another program and some function work), I'm not seeing how to represent time zone info in the date/time format.
    Could someone please point me towards how time zone info is packed/unpacked into whatever time format Numbers is using?

    Hm.  Thanks, but that wouldn't really help with the time math like durations or using date/time values as coordinates for graphs.
    I've converted them all to GMT which works for most of the math but leaves me with a lousy presentation since the times are completely off.  It doesn't work very well to say that certain events are more common at 5:00 GMT than at 8:00 GMT when we're in GMT+8, (or GMT+7 for part of the year).  People tend to ignore the time zone when reading the report and then get confused because the times don't match their expectations.
    And I really don't want to implement GMT -> localtime conversions, not even for one time zone.  :\.
    Thank you for the confirmation that Numbers is broken on this rather than that I was missing something.

  • Customising SYSDATE using time-zone offset

    Situation:
    A database instance is configured with multiple schemas with each holding data for a company. A set of Oracle Forms and Reports programs has been developed to run against each of these schemas.
    However, there are few overseas companies phyiscally located in different time zone with respect to the database location.
    Is there a way to "customise" sysdate to generate "adjusted" date/time value using the time zone offset "without changing the programs" (in Forms, Reports and dbms)? Most of the programs use sysdate to populate date-specific fields.
    Please advise.
    Thanks

    Sysdate is sysdate-- it can't be changed on a session-by-session basis. You could write your own sysdate-like function, but that would require code changes. If you are making code changes, and you're on 9i, I would suggest using a TIMESTAMP WITH TIMEZONE data type.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How to get current time

    Hi,
    I would like to know how to get the current time (07H25 for instance).
    Does someone know how to do it ?
    Thanks in advance, Fred.

    java.util.Date = new java.util.Date();
    The above code produces an object which contains a timestamp (date and time) for the instance in which it was created.
    To display it in any format you wish you would use the java.text.SimpleDateFormat class.

  • How to get current time in seconds

    Can someone please tell me how to get the current time in seconds. I am currently doing as follows but not sure if its correct or best way:
    Calendar cal = new GregorianCalendar();
    long currentTimeInSeconds = cal.getTimeInMillis()/1000;

    vik1491 wrote:
    How about this:
    Date date = new Date();
    Format formatter = new SimpleDateFormat("HH:mm:ss");
    String s = formatter.format(date);
    String patternStr = "\\:";
    String[] fields = s.split(patternStr);
    int secondsSinceMidnight= Integer.parseInt(fields[0]) * 3600 + Integer.parseInt(fields[1]) * 60 + Integer.parseInt(fields[2]);
    What about the day what you switch between standard time and daylight savings time?

  • Anyone know how to get current time using Java?

    Hi,
    do anyone know how to use system.currentTimeMillis() to get the current time?
    I know that system.currentTimeMillis() get the time between current time and midnight, January 1, 1970 UTC. but how to use it to get the current time format?
    Thank you very much.

    Hi,
    do anyone know how to use system.currentTimeMillis()
    to get the current time?
    I know that system.currentTimeMillis() get the time
    between current time and midnight, January 1, 1970
    UTC. but how to use it to get the current time format?
    Thank you very much.
    long timeInMillis = System.currentTimeMillis();
    Calendar c = Calendar.getInstance();
    c.setTime(timeInMillis);
    Date d = c.getTime();And format using SimpleDateFormat:
    SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-yyyy HH:mm:ss");
    String formattedDateString = sdf.format(d);

Maybe you are looking for

  • Use of open interface tables in R12

    Hello, Can someone tell me the status of using open interface tables in release 12. Is this still a supported mechanism for importing data into the product, or must you use a PL/SQL/Java API, XML gateway etc? iREP for 11.5.10 lists these open interfa

  • Home Sharing issue with multiple iTunes libraries

    I'm hoping someone out there has a suggestion to help solve the problem I'm having with the new iOS 4.3 Home Sharing. I have an iMac and a MacBook Pro both running the latest system and iTunes versions. Each has an iTunes library with Home Sharing tu

  • Non-editable element in an InDesign document.

    Hello, all. I need to add a non editable element to my InDesign document. This element will be my copyright notice. Although I will be sharing this InDesign document with others and will allow them to modify or customize it to their needs I wish to m

  • Sending message to perticular ip address

    Hi experts,                   It is possible to send a chat message to a perticular person using his ip address.I have tried TH_POPUP function module but it is only based on the user.My requirment is to send chat message to perticular ip address.is a

  • City ID - Subscription or Continue Free Trial

    An app that came preinstalled on my Droid X called "CityID" has taken over my screen on its own. I don't believe I launched this app. The screen is telling me that I either should subscribe to City ID for a monthly fee, or I can "continue free trial"