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

风流意气都作罢 提交于 2019-12-03 04:46:31
jlehr

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!