比较Cocoa中的日期 [英] Comparing dates in Cocoa

查看:126
本文介绍了比较Cocoa中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi我想知道如何获取当前日期?
i要使用以下代码将当前日期与从plist文件中提取的日期进行比较。

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"];

以进行比较im使用以下代码

for comparison i m using the following code

if([curDate compare:expDate] == NSOrderedAscending )

但它不工作。

推荐答案

为了教导别人如何钓鱼而不只是喂他:

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.

这些指南还有指向所使用的特定类的文档的链接。在这种情况下, NSDate类参考,其中包含创建日期比较日期

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.

编辑

为了回答您对此问题的评论无效,我认为问题可能是您没有创建对象作为NSDate存储在字典中。再次。请查看创建日期文档。它将是像

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

NSDate *expiryDate = [NSDate dateWithNaturalLanguageString:@"31/01/10"];

但这只是一个例子,还有其他设置日期字符串的方法。

But this is just an example, there are other ways of setting a date string.

这篇关于比较Cocoa中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆