简体   繁体   中英

HTTP date format to NSDate

I have a date string (well, NSData, but that's easy to convert to a string) that's in what I believe is the format the HTTP standard uses:

Mon Apr 17 19:34:46 UTC 2006

Is there any better (ie less error-prone) way to parse that than specifying the format string by hand in an NSDateFormatter?

(My application is an iPhone app, but I suspect standard Cocoa solutions will work too, since NSDate and NSDateFormatter are part of Foundation.)

No, I don't think there is a better way.

If you have some outside input, you must know the format of your input beforehand, and you can only prepare for problems, ie a fail over parser with an alternate NSDateFormatter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM