• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDate from xsd:dateTime / ISO 8601
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDate from xsd:dateTime / ISO 8601


  • Subject: Re: NSDate from xsd:dateTime / ISO 8601
  • From: Nathan Vander Wilt <email@hidden>
  • Date: Mon, 17 Mar 2008 18:05:13 -0700

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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >NSDate from xsd:dateTime / ISO 8601 (From: Nathan Vander Wilt <email@hidden>)
 >Re: NSDate from xsd:dateTime / ISO 8601 (From: Jens Alfke <email@hidden>)
 >Re: NSDate from xsd:dateTime / ISO 8601 (From: Nathan Vander Wilt <email@hidden>)

  • Prev by Date: Re: Apple Events and automatic AutoReleasePool managment
  • Next by Date: Re: How to track all keyboard event?
  • Previous by thread: Re: NSDate from xsd:dateTime / ISO 8601
  • Next by thread: Re: NSDate from xsd:dateTime / ISO 8601
  • Index(es):
    • Date
    • Thread