tranvutuan
tranvutuan

Reputation: 6109

Cannot convert to NSDate from string

Below are the date strings received from the server

2012-07-05T11:18:00-04:00 or 2012-12-05T10:26:00-05:00

As far as I know 04:00 and 05:00 are the numeric time zone offset. They may be +04:00 or +05:00

My question is:

How can I set setDateFormat for NSDateFormat if the time zone offset are varied right now?

Please advice me on this issue if you have any clues

All comments are welcomed here.

Edited: If i do this:

NSDateFormatter *format                 =   [[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'-'04':'00"];

It won't work with if the date string is 2012-12-05T10:26:00-05:00.Therefore I am looking for a general format so that it can work for both cases

Upvotes: 0

Views: 190

Answers (1)

GoZoner
GoZoner

Reputation: 70165

Try @"yyyy-MM-dd'T'HH:mm:ssZZZ" or perhaps @"yyyy-MM-dd'T'HH:mm:ss ZZZ" as the setDateFormat: argument.

Upvotes: 2

Related Questions