我有格式为 2016-04-27T08:06:07.531Z 的日期字符串,并希望转换为 2016.04.27。我试过下面的代码
NSString *dateString = @"2016-04-27T08:06:07.531Z";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat"yyyy-MM-ddTHH:mm:ss.Z"];
NSDate *dateReceived = [dateFormatter dateFromString:dateString];
[dateFormatter setDateFormat"dd.MM.YYYY"];
NSString *dateReq = [dateFormatter stringFromDate:dateReceived];
NSLog(@"Date Req:%@",dateReq);
我在 NSLog 的控制台中得到空值。任何帮助将不胜感激。谢谢。
Best Answer-推荐答案 strong>
使用喜欢
NSString *dateString = @"2016-04-27T08:06:07.531Z";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
NSDate *dateReceived = [dateFormatter dateFromString:dateString];
// 2016.04.27
[dateFormatter setDateFormat"yyyy.MM.dd"];
NSString *dateReq = [dateFormatter stringFromDate:dateReceived];
NSLog(@"Date Req:%@",dateReq);
关于ios - 将日期字符串(2016-04-27T08 :06:07. 531Z) 转换为特定日期格式 dd.MM.YYYY,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/36907651/
|