Get the time and date of selected time zone?

前端 未结 2 771
栀梦
栀梦 2020-12-22 05:41

I tried below snippet I\'m getting current date and time of system instead of the selected time zone code.

NSDate *now = [NSDate date];
NSCalendar *gregorian         


        
2条回答
  •  隐瞒了意图╮
    2020-12-22 06:47

    [dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss z"];
    

    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

    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.

提交回复
热议问题