将 NSString 转换为 NSDate
我有日期字符串:2010 年 10 月 11 日星期一。如何从中创建一个 NSDate 对象,然后从中获取不同的组件,例如日、月、日期、年。请注意,该字符串的格式/区域设置可能会在运行时发生变化。
I have date string: Monday, October 11, 2010. How can I create a NSDate object out of it and then get different components like day, month, date, year from it. Please note that format/locale of this string may change at runtime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 NSDateFormatter 创建 NSDate,然后您可以通过 NSDate 属性访问其组件(您需要调整下面的格式字符串):
Use an NSDateFormatter to create the NSDate, then you can access its components through NSDate properties (you'll need to adjust the format string below):
另一种可能性:
another possibility: