比较 Cocoa 中的日期

发布于 2024-08-13 04:40:57 字数 273 浏览 2 评论 0原文

你好,我想知道如何获取当前日期? 我想将当前日期与使用以下代码从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光礼记 2024-08-20 04:40:57

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

看看 日期和时间编程指南。。文档中的编程指南是您尝试理解某个主题时的第一站。它们概述了可以做什么,并包含有用的示例代码。

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

编辑

为了回答您对此不起作用的评论,我认为问题可能是您尚未创建作为 NSDate 存储在字典中的对象。再次。看看 创建日期文档。它将类似于

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

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

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

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

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

一刻暧昧 2024-08-20 04:40:57

要获取当前日期,只需使用:

NSDate * today = [NSDate date];

与另一个日期进行比较:

if ([today compare:expirationDate] == NSOrderedAscending)
{
    // today's date is before the expiration date
}

To get the current date, simply use:

NSDate * today = [NSDate date];

To compare to another date:

if ([today compare:expirationDate] == NSOrderedAscending)
{
    // today's date is before the expiration date
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文