Convert NSDate to NSString with NSDateFormatter with TimeZone without GMT Time Modifier

前端 未结 2 1305
醉梦人生
醉梦人生 2021-02-07 03:13

I\'m initializing my NSDateFormatter thusly:

NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setLocale:[[[NSLocale          


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 04:10

    Accepted answer had a typo.

    On the other hand, if you just want to display the timezone name, just make the 'z' uppercase.

    leave the 'z' lowercase for named timezone, i.e. PST and uppercase 'Z' for -0800

        NSDateFormatter *format = [[NSDateFormatter alloc] init];
        [format setDateFormat:@"MMMM dd, yyyy (EEEE) HH:mm:ss z Z"];
        NSDate *now = [NSDate date];
        NSString *nsstr = [format stringFromDate:now];
    

    //January 23, 2013 (Wednesday) 12:33:46 PST -0800

提交回复
热议问题