设置自定义DateFormat

时间:2016-02-12 10:18:26

标签: ios date nsdateformatter date-formatting

NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE MMM dd yyyy HH:mm:ss zzz (zzzz)"];
NSLog(@"%@",[dateFormatter stringFromDate:[NSDate date]]);

Abow代码给出了Fri Feb 12 2016 14:11:16 GMT+5:30 (India Standard Time)日期格式结果,但我需要Fri Feb 12 2016 14:11:16 GMT 05:30 (India Standard Time)日期结果格式

1 个答案:

答案 0 :(得分:1)

试试这个。

NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"EEE MMM dd yyyy HH:mm:ss zzz (zzzz)"];
    [dateFormatter stringFromDate:[NSDate date]];
    NSString *date=[dateFormatter stringFromDate:[NSDate date]];
     //Replace "+" with Space""
    NSString *finalTimezone = [date stringByReplacingOccurrencesOfString:@"+"
                                                                    withString:@" "];

<强>输出:

enter image description here