如何将 NSString 转换为 NSDate?
我绞尽脑汁也没有运气。有人可以告诉我如何将此字符串:
“2011-01-13T17:00:00+11:00”
转换为 NSDate 吗?
Ive been racking my brains with no luck. Could someone please tell me how i would convert this string:
"2011-01-13T17:00:00+11:00"
into a NSDate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
unicode日期格式文档位于此处
另外,根据您的情况,您可以尝试以下操作:
希望这个有帮助。
The unicode date format doc is here
Also, for your situation, you could try this:
Hope this helps.
将 T 部分放在单引号中,并检查 unicode 文档以了解确切的格式。就我而言,我有类似的东西,我这样做:
同样,不完全相同,但你明白了。另外,在字符串和 nsdate 之间来回转换时请注意时区。
同样,就我而言,我使用:
put the T part in single quotes, and check the unicode docs for the exact formatting. In my case, I have something similar, which I do this:
Again, not exactly the same, but you get the idea. Also, be careful of the timezones when converting back and forth between strings and nsdates.
Again, in my case, I use:
你试过这个
干杯吗
Did you try this
Cheers
您可以查看 TouchTime。
https://github.com/jheising/TouchTime。
它是 PHP 5.4 中很棒的 strtotime 函数的直接移植,适用于 Cocoa 和 iOS。它将接受几乎任何任意格式的日期或时间字符串并将其转换为 NSDate。
希望它有效,并享受!
You might check out TouchTime.
https://github.com/jheising/TouchTime.
It's a direct port of the awesome strtotime function in PHP in 5.4 for Cocoa and iOS. It will take in pretty much any arbitrary format of date or time string and convert it to an NSDate.
Hope it works, and enjoy!
尝试使用这个支持 cocoapods 的项目。可能还需要许多附加功能。
“一个用一些便利功能扩展 Cocoa 的 NSDate 类的类别。”
https://github.com/billymeltdown/nsdate-helper
这是他们页面上的示例:
Try using this cocoapods enabled project. There are many added functions that will probably be needed as well.
"A category to extend Cocoa's NSDate class with some convenience functions."
https://github.com/billymeltdown/nsdate-helper
Here's an example from their page: