views:

46

answers:

1

I am having a problem converting a date/time string to an NSDate.

The date string I need to convert is: 2002-12-24T00:00:00-07:00

My date format string is currently yyyy-MM-dd'T'HH:mm:ssZZZ

The problem is the colon in the time zone.

ZZZ returns a string like: -0700 (without the colon) How can I convert a string WITH a colon in the time zone?

Thanks

+1  A: 

I suggest doing some string manipulation so it is in a form that dateWithString can more easily accept - how about using stringByReplacingOccurrencesOfString one or more times to get rid of the colon?

dateWithString wants:

YYYY-MM-DD HH:MM:SS ±HHMM

you have:

yyyy-MM-dd'T'HH:mm:ssZZZ

You will probably need to use some combination of componentsSeparatedByString (to get rid of the 'T' part, unless you have a small range of values possible for T, and perhaps write yourself a small function to convert ssZZZ into +HHMM.

Adam Eberbach
The 'T' will handle the T so all I had to get rid of was the colon between the time zone parts. My concern was that was the 'easy' way around the problem, but not the proper way. However from everyone I have talked to about this, it seems to be really the only way to do it. Since my string is always the same format I can do a stringByReplacingOccurrencesOfString:withString:options:range: and set the range to be 1 in length and 3 from the end of the string
kdbdallas