【问题标题】:IOS Time zone abbreviation without GMT offset. Need directly like IST,EST etc没有 GMT 偏移量的 IOS 时区缩写。需要直接像IST,EST等
【发布时间】:2017-07-26 13:04:52
【问题描述】:
 NSTimeZone *timezone = [NSTimeZone systemTimeZone];
 NSString *timeZoneAbberivation = [timezone abbreviation];

timeZoneAbberivation 像 GMT+5:30 那样打印。但我需要将 GMT+5:30 打印为 IST。 (IST 属于印度/加尔各答)。

假设如果是美国/纽约时区,我需要它作为 EST 等。

【问题讨论】:

  • 您是否尝试过进行查找?应该很标准!!

标签: ios objective-c nstimezone


【解决方案1】:

您可以使用NSDateFormatter。查看提供“短特定非位置格式”的z 格式参数

NSDateFormatter Date Formatting Table

【讨论】:

    【解决方案2】:

    在 Swift 中你可以这样使用:

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

    在 Objective-C 中你可以使用这个:

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

    【讨论】:

    • 这不是你从timeZone.name得到的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-26
    • 2022-11-25
    • 2012-11-28
    • 2013-10-15
    • 2020-10-21
    • 1970-01-01
    相关资源
    最近更新 更多