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

前端 未结 2 1301
醉梦人生
醉梦人生 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:01

    Remove the trailing 'z' character from the format string if you don't want to display the time zone.

    EDIT

    On the other hand, if you just want to display the timezone name, just make the 'z' uppercase. ((edit: leave the 'z' lowercase for named timezone, i.e. PST and uppercase 'Z' for -0800))

    EDIT

    Lowercase 'z' works fine for all the other timezones, but unfortunately GMT is a special case. So the easiest thing to do is to just omit the 'z' and append " GMT" to the formatted date.

提交回复
热议问题