mohan kumar
mohan kumar

Reputation: 41

IOS Time zone abbreviation without GMT offset. Need directly like IST,EST etc

 NSTimeZone *timezone = [NSTimeZone systemTimeZone];
 NSString *timeZoneAbberivation = [timezone abbreviation];

timeZoneAbberivation is printing like GMT+5:30 like that. But I need GMT+5:30 to be printed as IST. (IST is of India/Kolkatta).

Suppose if it is America/Newyork time zone, I need it as EST, etc.

Upvotes: 4

Views: 737

Answers (2)

vikram
vikram

Reputation: 181

In Swift you can use this:

let  zone = TimeZone.current.identifier
print(zone)

In Objective-C you can use this:

NSTimeZone* timeZone = [NSTimeZone timeZoneWithAbbreviation:@"IST"];

NSString* timeZoneName = [timeZone localizedName:NSTimeZoneNameStyleStandard 
                                          locale:[NSLocale currentLocale]];
NSLog(@"Name : %@", timeZoneName);

Upvotes: 0

Stonz2
Stonz2

Reputation: 6396

You can use an NSDateFormatter. Look into the z format argument which supplies the "short specific non-location format"

NSDateFormatter Date Formatting Table

Upvotes: 3

Related Questions