比较 Cocoa 中的日期
你好,我想知道如何获取当前日期? 我想将当前日期与使用以下代码从 plist 文件中获取的日期进行比较。
NSDate *expDate = [licenseDictionary objectForKey:@"Expires"];
为了进行比较,我使用以下代码,
if([curDate compare:expDate] == NSOrderedAscending )
但它不起作用。谁能帮助我。
hi i want to know how to get current date?
i want to compare current date with a date i m fetching from a plist files using following code.
NSDate *expDate = [licenseDictionary objectForKey:@"Expires"];
for comparison i m using the following code
if([curDate compare:expDate] == NSOrderedAscending )
but its not working. can anybody help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了教别人如何钓鱼而不仅仅是喂他:
看看 日期和时间编程指南。。文档中的编程指南是您尝试理解某个主题时的第一站。它们概述了可以做什么,并包含有用的示例代码。
这些指南还包含指向所使用的特定类的文档的链接。在这种情况下,有 NSDate 类参考 其中有关于 创建日期 和 比较日期。
编辑
为了回答您对此不起作用的评论,我认为问题可能是您尚未创建作为 NSDate 存储在字典中的对象。再次。看看 创建日期文档。它将类似于
但这只是一个示例,还有其他设置日期字符串的方法。
In the interest of teaching someone how to fish rather than just feeding him:
Have a look at the Date and Time Programming Guide.. The Programming Guides in the documentation are your first stop when trying to understand a topic. They provide an overview of what can be done and contain useful example code.
These guides also have links to the documentation of the specific classes that are used. In this case there is the NSDate Class Reference which has sections on creating dates and comparing dates.
Edit
To answer you comment about this not working, I think the problem could be that you haven't created the object that you've stored in the dictionary as an NSDate. Again. Have a look at the creating dates documentation. It will be something like
But this is just an example, there are other ways of setting a date string.
要获取当前日期,只需使用:
与另一个日期进行比较:
To get the current date, simply use:
To compare to another date: