PAn Kaj Khatri
PAn Kaj Khatri

Reputation: 539

How to get full time zone name ios

How do we get full time zone name in iOS like Indian Standard Time instead of IST.

NSTimezone *timeZone=[NSTimeZone localTimeZone];

i am getting GMT but i want it like full form string

Upvotes: 9

Views: 12930

Answers (3)

Alaeddine
Alaeddine

Reputation: 6212

You can get the name from the name property:

 NSTimeZone *timeZone = [NSTimeZone localTimeZone];
 NSLog(@"Name: %@", timeZone.name);

Result:

2015-07-10 13:31:46.292 APP[2904:50429] Name : Asia/Calcutta

You can to get the name with the desired style NSTimeZoneNameStyle using - localizedName:locale:

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

Result:

2015-07-10 13:36:31.771 APP[2940:51197] Name : India Standard Time

If you call [NSTimeZone abbreviationDictionary] you'll get a dictionary containing all available abbreviations.

NSLog(@"%@",[NSTimeZone abbreviationDictionary]);

Result :

2015-07-10 11:44:05.954 APP[1472:26120] {
    ADT = "America/Halifax";
    AKDT = "America/Juneau";
    AKST = "America/Juneau";
    ART = "America/Argentina/Buenos_Aires";
    AST = "America/Halifax";
    BDT = "Asia/Dhaka";
    BRST = "America/Sao_Paulo";
    BRT = "America/Sao_Paulo";
    BST = "Europe/London";
    CAT = "Africa/Harare";
    CDT = "America/Chicago";
    CEST = "Europe/Paris";
    CET = "Europe/Paris";
    CLST = "America/Santiago";
    CLT = "America/Santiago";
    COT = "America/Bogota";
    CST = "America/Chicago";
    EAT = "Africa/Addis_Ababa";
    EDT = "America/New_York";
    EEST = "Europe/Istanbul";
    EET = "Europe/Istanbul";
    EST = "America/New_York";
    GMT = GMT;
    GST = "Asia/Dubai";
    HKT = "Asia/Hong_Kong";
    HST = "Pacific/Honolulu";
    ICT = "Asia/Bangkok";
    IRST = "Asia/Tehran";
    IST = "Asia/Calcutta";
    JST = "Asia/Tokyo";
    KST = "Asia/Seoul";
    MDT = "America/Denver";
    MSD = "Europe/Moscow";
    MSK = "Europe/Moscow";
    MST = "America/Denver";
    NZDT = "Pacific/Auckland";
    NZST = "Pacific/Auckland";
    PDT = "America/Los_Angeles";
    PET = "America/Lima";
    PHT = "Asia/Manila";
    PKT = "Asia/Karachi";
    PST = "America/Los_Angeles";
    SGT = "Asia/Singapore";
    UTC = UTC;
    WAT = "Africa/Lagos";
    WEST = "Europe/Lisbon";
    WET = "Europe/Lisbon";
    WIT = "Asia/Jakarta";
}

Upvotes: 15

Ganee....
Ganee....

Reputation: 302

I think you are looking for this

NSDictionary *tempDict = [NSTimeZone abbreviationDictionary];
NSTimeZone* timeZone;
NSString* timeZoneName;

for(NSString *str in tempDict){
    timeZone = [NSTimeZone timeZoneWithAbbreviation:str];
    timeZoneName = [timeZone localizedName:NSTimeZoneNameStyleStandard locale:[NSLocale currentLocale]];
    NSLog(@"%@ --- %@", timeZoneName,timeZone);

}

Output will be like...

Eastern Standard Time --- America/New_York (EDT) offset -14400 (Daylight) Atlantic Standard Time --- America/Halifax (ADT) offset -10800 (Daylight)

Upvotes: 1

Shoaib
Shoaib

Reputation: 2294

Try this;

NSTimeZone* timeZone = [NSTimeZone localTimeZone];
NSString* timeZoneName = [timeZone localizedName:NSTimeZoneNameStyleStandard locale:[NSLocale currentLocale]];

NSLog(@"timeZoneName : %@", timeZoneName);

Upvotes: 8

Related Questions