我正在尝试为“2013-12-02T12:15:43.182Z”设置日期格式。我使用了该代码:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ssS''Z'"];
如何设置此日期格式?
答案 0 :(得分:6)
Ues this:
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
NSDate *dateConverted = [dateFormatter dateFromString:@"2013-12-02T12:15:43.182Z"];
NSLog(@"%@",dateConverted);
答案 1 :(得分:3)
这可能对你有用..
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
答案 2 :(得分:0)
这可能会对你有帮助,
NSDate *myDate = [NSDate date];
NSDateFormatter * df = [[NSDateFormatter alloc] init];
[df setTimeZone:[NSTimeZone systemTimeZone]];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
NSLog(@"Required date format: %@",[df stringFromDate:myDate]);