开发者

NSDateFormatter Date Format for date/time with colon in Time Zone

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜