Rectangle 27 13

The change in parsing of abbreviated time zone names in iOS 5.0 is a result of an intentional change in the open-source ICU 4.8 library (and the open-source CLDR 2.0 data that it uses), a modified version of which is used to implement some of the NSDateFormatter functionality.

The issue is this: With the short timezone formats as specified by z (=zzz) or v (=vvv), there can be a lot of ambiguity. For example, "ET" for Eastern Time" could apply to different time zones in many different regions. To improve formatting and parsing reliability, the short forms are only used in a locale if the "cu" (commonly used) flag is set for the locale. Otherwise, only the long forms are used (for both formatting and parsing).

For the "en" locale (= "en_US"), the cu flag is set for metazones such as Alaska, America_Central, America_Eastern, America_Mountain, America_Pacific, Atlantic, Hawaii_Aleutian, and GMT. It is not set for Europe_Central.

However, for the "en_GB" locale, the cu flag is set for Europe_Central.

So a formatter set for short timezone style "z" or "zzz" and locale "en" or "en_US" will not parse "CEST" or "CET", but if the locale is instead set to "en_GB" it will parse those. The "GMT" style will be parsed by all.

If the formatter is set for the long timezone style "zzzz", and the locale is any of "en", "en_US", or "en_GB", then any of the following will be parsed, because they are unambiguous: "Pacific Daylight Time" "Central European Summer Time" "Central European Time"

Heath, Yes, you are correct, for the example you provided above, [dateFormatter stringFromDate:[NSDate date]] should use the short time zone name "IST". The fact that it does not is due to a deficiency in the "en_IN" locale data in the versions of CLDR data used by ICU in the current OSX and iOS releases (CLDR 1.9.1 and 2.0 respectively). The "en_IN" locale in those CLDR versions did not override or supplement any of the timezone name data from the base "en" locale, whose default content is for "en_US".

This is already fixed for the CLDR 21 release coming in a few days. That is being incorporated into ICU 49 which will be picked up in future OSX and iOS releases.

According to the unicode documentation on formats and their rules, the V format may have been a better choice:

...the same format as z, except that metazone timezone abbreviations are to be displayed if available, regardless of the value of [the] commonlyUsed [flag].

NSLocale *indianEnglishLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_IN"] autorelease];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Kolkata"];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setLocale:indianEnglishLocale];
[dateFormatter setDateFormat:@"V"];
[dateFormatter setTimeZone:timeZone];

NSLog(@"V date string: %@", [dateFormatter stringFromDate:[NSDate date]]);

I receive the following output:

V date string: IST

Same issue as Smitha... print inccu instead of IST

I tried below dateFormatting string [dateFormatter setDateFormat:@"z"]; and its works perfectly.

ios - NSDateFormatter doesn't show time zone abbreviation for "Asia/Ko...

ios nsdateformatter
Rectangle 27 0

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm a";

    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [dateFormatter setTimeZone:gmt];
    NSString *timeStamp = [dateFormatter stringFromDate:[NSDate date]];
    NSLog(@"time in GMT ------ %@",timeStamp);



    NSTimeZone *localTime = [NSTimeZone systemTimeZone];
    NSLog(@"local timezone  is------ %@",[localTime name]);


    NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [dateFormatter setTimeZone:sourceTimeZone];
    NSDate *dateFromString = [dateFormatter dateFromString:timeStamp];
    NSLog(@"local time is ------- %@",dateFromString);


    NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
    dateFormatter1.dateFormat = @"yyyy-MM-dd HH:mm";

    NSTimeZone *gmt1 = [NSTimeZone localTimeZone];
    [dateFormatter1 setTimeZone:gmt1];
    NSString *timeStamp1 = [dateFormatter1 stringFromDate:[NSDate date]];
    NSLog(@"local time is ------- %@",timeStamp1);
time in GMT ------ 2013-05-10 05:13 AM
 local timezone  is------ Asia/Kolkata
 local time is ------- 2013-05-10 00:13:00 +0000
 local time is ------- 2013-05-10 10:43
timestamp
NSDate

iphone - Issue in coverting GMT time to Local time - Stack Overflow

iphone ios nsdateformatter gmt nstimezone
Rectangle 27 0

//This is basic way to get time of any GMT time.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm a"];  // 09:30 AM
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:1]]; // For GMT+1
NSString *time = [formatter stringFromDate:[NSDate date]];  // Current time

Convert UTC NSDate to local Timezone Objective-C - Stack Overflow

objective-c timezone nsdate
Rectangle 27 0

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm";

    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [dateFormatter setTimeZone:gmt];
    NSString *timeStamp = [dateFormatter stringFromDate:[NSDate date]];
    [dateFormatter release];

Does the DateFormatter work with both "%d" type codes... and just "d" type codes?

@Donna: The latest NSDateFormatter uses the UTS#35 standard. unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns . It will not work with the C style %d syntax.

Old thread, but I also encourage using Howard's approach instead of messing with the date itself as some of the other suggestions do. Worth noting is that the "description" of an NSDate is always in GMT. This implies that an NSLog(@"%@", [NSDate date]) always shows the given date in GMT as well.

What is this 'T' in there? it shows up as is in timeStamp

I'd like to elaborate on Olaf's comment by adding that not only does an NSDate description show the date/time in GMT, but the timeIntervalSinceReferenceDate reflects the number of seconds since 2001-01-01 in GMT (not in your local time zone), too.

iphone - NSDate - Convert Date to GMT - Stack Overflow

iphone ios nsdate gmt
Rectangle 27 0

An NSDate represents a concrete point in time, regardless of the timezone. Put another way, an NSDate does not have a timezone. Timezones are only relevant when you want to display the date to the user. So 9:30pm in Mountain Time is 3:30am (+1 day) in GMT (assuming a 6 hour time difference).

NSDate, since it does not have a timezone, must pick one when producing a human-readable version to return as its -description. To make things simple, it always returns a date formatted in the GMT time zone. If you would like the date formatted to be in a different timezone, you can set the -timezone property of an NSDateFormatter, and then convert the date into a string using the -stringFromDate: method.

NSDate / NSDateFormatter returning GMT on iPhone iOS 4.3 - Stack Overf...

iphone nsdate
Rectangle 27 0

There's nothing to fix. NSLog is outputting the date in GMT/UTC. If you want it in your local timezone, you need to use NSDateFormatter.

i did, but with no success

objective c - Unexpected output from NSDate - Stack Overflow

objective-c ios xcode nsdate
Rectangle 27 0

Just use NSDateFormatter with the formatting string eee, dd MMM yyyy HH:mm:ss zzz. The Zs at the end cause it to read the time zone from the string.

NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setLocale:usLocale];
[formatter setDateFormat:@"eee, dd MMM yyyy HH:mm:ss zzz"];
_createdAt = [formatter dateFromString:dateString];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; [dateFormatter setTimeZone:gmt];

You don't need that because your string specifies GMT in it and the zzz component of the date format you've set will tell NSDateFormatter to use what your string specifies rather than whatever it considers the norm to be.

objective c - NSDateFormatter: how to convert date string with 'GMT' t...

objective-c ios nsdate nsdateformatter
Rectangle 27 0

NSString* string=@"26-01-2014";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-mm-yyyy"];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormatter setTimeZone:gmt];

NSDate *date = [dateFormatter dateFromString:string];
NSLog(@"Date = %@",date);

ios - Time between date from string and current time in GMT - Stack Ov...

ios objective-c nsdate
Rectangle 27 0

Dont base your result on NSLoging NSDate, since logging it will give you the time in GMT Please refer to my answer on this question NSDateFormatter giving me time 4 hours ahead

For example if you want to fire a UILocalNotification at 4:39 am you would do the following

NSCalendar* myCalendar = [NSCalendar currentCalendar];
NSDateComponents* components = [myCalendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit 
                                             fromDate:[NSDate date]];
//4:39 Am
[components setHour: 4]; //4 am
[components setMinute: 39];//39 minutes
[components setSecond: 0];// 0 seconds
NSDate *myDate = [myCalendar dateFromComponents:components];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMMM dd, yyyy h:mma"];  
NSString *str = [formatter stringFromDate:myDate];

NSLog(@"date is %@", myDate); //This will log the correct data but in GMT time zone
NSLog(@"date is %@", str); //This will log the correct data

UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = myDate;

@KAREEMMAHAMMED check the updated i done to my answer, also please dont forget to accept and/or upvote if the answer was helpful :)

objective c - Getting wrong date from NSDateFormatter from dateFromStr...

objective-c ios nsstring nsdate nsdateformatter
Rectangle 27 0

NSDate is a reference to an interval from an absolute reference date, January 1, 2001 00:00 GMT. So the class method [NSDate date] will return a representation of that interval. To present that data in a textual format in UTC, just use the NSDateFormatter with the appropriate NSTimeZone (UTC) to render as needed.

iphone - Objective-C setting NSDate to current UTC - Stack Overflow

iphone objective-c ios nsdate utc
Rectangle 27 0

Logging an NSDate in the debugger is somewhat misleading as it gives you a calendar day and time for a particular time zone - UTC / GMT. However, NSDate has no inherent time zone or any inherent relationship to how humans perceive and think about dates at all. Instead, it is a timestamp. Classes like NSDateComponents, NSTimeZone, NSDateFormatter, and so on all exist to provide human context and formatting.

So what you see is the timestamp formatted to that particular format and UTC time zone, which is how NSDate will always appear when printed in the debugger or the console. If you were to calculate the time zone offset between UTC and your own time zone, you'd find that the date represents the time stamp you gave it, and not one however many hours off.

ios - Need information on printing [NSDate date] - Stack Overflow

ios nsdate
Rectangle 27 0

//This is basic way to get time of any GMT time.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm a"];  // 09:30 AM
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:1]]; // For GMT+1
NSString *time = [formatter stringFromDate:[NSDate date]];  // Current time

objective c - iOS: Convert UTC NSDate to local Timezone - Stack Overfl...

ios objective-c swift timezone nsdate
Rectangle 27 0

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm";

    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [dateFormatter setTimeZone:gmt];
    NSString *timeStamp = [dateFormatter stringFromDate:[NSDate date]];
    [dateFormatter release];

Does the DateFormatter work with both "%d" type codes... and just "d" type codes?

@Donna: The latest NSDateFormatter uses the UTS#35 standard. unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns . It will not work with the C style %d syntax.

Old thread, but I also encourage using Howard's approach instead of messing with the date itself as some of the other suggestions do. Worth noting is that the "description" of an NSDate is always in GMT. This implies that an NSLog(@"%@", [NSDate date]) always shows the given date in GMT as well.

What is this 'T' in there? it shows up as is in timeStamp

I'd like to elaborate on Olaf's comment by adding that not only does an NSDate description show the date/time in GMT, but the timeIntervalSinceReferenceDate reflects the number of seconds since 2001-01-01 in GMT (not in your local time zone), too.

ios - NSDate - Convert Date to GMT - Stack Overflow

ios objective-c swift nsdate gmt
Rectangle 27 0

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[formatter setTimeZone:timeZone];

NSDate *now = [NSDate date];
NSString *dateAsString = [formatter stringFromDate:now];

The only strange thing I see in your code it's that you use dateFormatter instead of dateTimeFormatter when set the NSTimeZone.

ios - NSDateFormatter stringFromDate: returning local time instead of ...

ios date datetime nsdate nsdateformatter
Rectangle 27 0

These are correct results. When you use NSLog to output an NSDate object, it displays in GMT. The parsing was done in your local timezone. NSDate objects are alway in GMT. If you want to print the NSDate object in your local timezone then you need an NSDateFormatter to print the date.

Note, that this is not totally correct: It is UTC, as GMT can differ from UTC due to the daylight saving time. GMT == (UTC+0|UTC+1) en.wikipedia.org/wiki/Greenwich_Mean_Time

@vikingosegundo Actually the docs state the time is output offset from GMT.

If you change the clock of you computer, and the location of the simulator to London, you will see, that for some dates you get +0100, na din winter +0000. I tried it out years ago. also: UTC is synonymous with GMT, but GMT is no longer precisely defined by the scientific community. en.wikipedia.org/wiki/UTC

I understand there is a difference between UTC and GMT. I'm saying the docs for NSDate state that the timezone used in the description method is GMT.

the docs are wrong. but the terms are easy to mix up.

objective c - NSDate Output incorrectly - Stack Overflow

objective-c ios cocoa-touch nsdate
Rectangle 27 0

isn't the "-04:00" at the end of the string telling NSDateFormatter that this date is GMT-4 and thus, it's just converting it to GMT ?

If not, please provide the full initialization of your NSDateFormatter.

ios - NSDateFormatter not recognizing timezone - Stack Overflow

ios objective-c cocoa-touch nsdate nsdateformatter
Rectangle 27 0

NSString *gmtDateString = @"20:45";

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[dateFormatter setDateFormat:@"HH:mm"];

//Now you have date in GMT time zone by default dateFormatter timezone would be in local time zone
NSDate *date = [dateFormatter dateFromString:dateString];

//set to local time zone
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];

//Now you have string in localDate format
NSString *localDateString = [dateFormatter stringFromDate:date];

iphone - NSDate from NSString adjusted to device timzone - Stack Overf...

iphone ios objective-c nsdate
Rectangle 27 0

// String To Date Conversion
NSString *dateStr = @"5/13/2012 6:05 am";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"M/d/yyyy h:mm a"];
NSDate *myDate = [dateFormatter dateFromString:dateStr];

// This converts time to GMT local timezone    
NSDateFormatter* df_local = [[[NSDateFormatter alloc] init] autorelease];
// calculate Number of seconds upto 5hrs(GMT+5000) seconds = 18000, if its GMT+0530 then seconds = 19800
// Set TimeZone Accordingly
[df_local setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:18000]];
// Set your Date Formate
[df_local setDateFormat:@"MM/dd/yyyy hh:mm:ss"];

// Your Final Output String
NSString* ts_local_string = [NSString stringWithFormat:@"%@ %@",[df_local stringFromDate:myDate],[[df_local timeZone] name]];
NSLog(@"Final string : %@",ts_local_string);

NSString* anotherFormat = [NSString stringWithFormat:@"%@ %@",[df_local stringFromDate:myDate],[[df_local timeZone] abbreviation]];
NSLog(@"OUtput : %@",anotherFormat);

OUTPUT : Final string : 05/13/2012 05:35:00 GMT+0500

how to get time zone as GMT+05:00 instead of GMT+0500

i have edited answer with your required format check it, let me know insights.

ios - Convert DateTime in iphone - Stack Overflow

iphone ios objective-c ipad datetime
Rectangle 27 0

Just use NSDateFormatter with the formatting string eee, dd MMM yyyy HH:mm:ss zzz. The Zs at the end cause it to read the time zone from the string.

NSLocale *usLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setLocale:usLocale];
[formatter setDateFormat:@"eee, dd MMM yyyy HH:mm:ss zzz"];
_createdAt = [formatter dateFromString:dateString];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; [dateFormatter setTimeZone:gmt];

You don't need that because your string specifies GMT in it and the zzz component of the date format you've set will tell NSDateFormatter to use what your string specifies rather than whatever it considers the norm to be.

objective c - NSDateFormatter: how to convert date string with 'GMT' t...

objective-c ios nsdate nsdateformatter
Rectangle 27 0

You will have to take the timezone into account. Your current timezone seems to be ahead of GMT. If you print the entire date with say a time stamp, then you will get the difference. So i suggest you add the timezone to the NSDateFormatter

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd/MM/yyyy"];
    dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    NSDate *date = [dateFormatter dateFromString:@"18/06/2014"];

    NSLog(@"Date : %@", date);

this is what I'm getting wholly: 2014-06-17 20:00:00 +0000

did you try the above code?

your timezone differs by how many hours from GMT

ios - Getting one date less - Stack Overflow

ios date