Friday, May 3, 2013

NSTimeZone abbreviation example ios


abbreviation

Returns the abbreviation for the receiver.
- (NSString *)abbreviation
Return Value
The abbreviation for the receiver, such as “EDT” (Eastern Daylight Time).
Discussion
Invokes abbreviationForDate: with the current date as the argument.
Example of [NSTimeZone abbreviation]
NSTimeZone* localTimeZone = [NSTimeZone localTimeZone];
NSString* localAbbreviation = [localTimeZone abbreviation];
To transform it back from the localAbbreviation, is just a matter to re-create the timeZone:
NSTimeZone* timeZoneFromAbbreviation = [NStimeZone timeZoneWithAbbreviation:abbreviation];
NSString* timeZoneIdentifier = timeZoneAbbreviation.name;

NSLog(@"Identifier: %@", timeZoneIdentifier); // Outputs America/Santiago for me.
Example of [NSTimeZone abbreviation]
NSTimeZone* localTimeZone = [NSTimeZone localTimeZone];
NSString* localAbbreviation = [localTimeZone abbreviation];
NSDictionary* abbreviationDictionary = [NSTimeZone abbreviationDictionary];
NSString* timeZoneID = 
[abbreviationDictionary objectForKey:localAbbreviation]; //should return 'America/Los_Angeles' if the abbreviation is ‘PDT’