문제

I Know it may be got answered a lot here but i think i have a different case

I'm getting the string date in the following format

2014-04-14 16:04:07 +0000

And using the following code

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *startDate = [dateFormat dateFromString:st];

But startDate always give me nil

도움이 되었습니까?

해결책

You should handle zone too. Correct variant:

[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];

Also consider to use nice lib for date formatting ISO8601DateFormatter. It will handle your format automatically.

다른 팁

[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

If that format does not match the format of the date string exactly, the result of dateFromString: is nil.

It doesn't so it is.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top