Does -dateWithString: really not support the
"international [standard!] string representation" of
ISO 8601?? What's the right way to convert such an
xsd:dateTime to an NSDate?

+[NSDate dateWithString:] is, I think, configured to recognize one particular date format, which depends on your system locale. It's not very useful. What you want to do is customize an NSDateFormatter object to recognize your format, and then parse using it.

Here's some code I wrote recently. [...]

Thanks, I'd forgotten about NSDateFormatter. I took your code snippets and made the following function:

NSDate* dateFromISO8601(NSString* str) {


I should note for posterity's sake that this function is poorly named: ISO 8601 is a versatile format with many representation options. I did come across http://boredzo.org/iso8601parser/, which is a category on NSCalendarDate that looks like it tries to cover everything. It takes a very low level, state machine(ish) approach to the problem.

I've killed an entire afternoon on this already, so for now I'll stick with a format of @"yyyy-MM-dd'T'HH:mm:ss'Z'". Unless I can prove I'll never get a file with sub-second date precision (or some other allowable variation of xsd:dateTime), I'll have to revisit this eventually. NSXML does seem to be able to take an NSCalendarDate as an objectValue (http://developer.apple.com/documentation/Cocoa/Conceptual/NSXML_Concepts/Articles/TransformObjectValues.html ), but I can only find this for emitted XML, and not during reading. I still hope this functionality is already in Cocoa somewhere, but it's looking less likely.

thanks,
-natevw
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to