无法从JSON调用中获取日期

时间:2021-01-15 22:25:47

I am pulling a date from JSON in the format of "1900-01-01T00:00:00-06:00"

我正在以“1900-01-01T00:00:00-06:00”的格式从JSON中提取日期

The code I am currently trying (and failing to parse with) is this

我目前正在尝试的代码(并且无法解析)就是这样

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZ"];
tempDate = [formatter dateFromString:trimmedString];

I then want to display what I pull in the MM-dd-yyyy format after I actually get the date back in the correct format.

然后,我想以正确的格式重新获得日期后,显示我在MM-dd-yyyy格式中输入的内容。

I am not sure of how many SSS and ZZ's I need at the end, and have tried multiple combinations to no avail. Any Suggestions?

我不知道最后我需要多少SSS和ZZ,并尝试了多种组合无济于事。有什么建议?

1 个解决方案

#1


3  

You need five "Z"s

你需要五个“Z”

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];

#1


3  

You need five "Z"s

你需要五个“Z”

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];