将字符串转换为 NSDate 的正确方法?(iphone)
在我的应用程序中,我将日期存储为字符串(“MM/dd/YYYY”格式)。在数据库中。稍后,当我检索字符串时,我必须比较两个日期,如何实现这一目标?
如果我使用“YYYY/MM/dd”格式,我可以直接将其作为字符串进行比较。 现在我必须使用“nsdateformatter”和“dateFromString”转换回 NSDate 对象。但无论我做什么,我都会使用它得到一个恒定的日期值。
有什么想法吗?
In my app I store the date as a string("MM/dd/YYYY" format). In the DB. later when I retrieve the string I have to compare two dates, how do I achieve this?
If I had used the"YYYY/MM/dd" format I could have directly compared it as strings.
Now I have to convert back into NSDate object using "nsdateformatter" and "dateFromString". But I get a constant date value using this no matter what I do.
Any ideas??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果:
Result: