获取 [NSDate date] 和字符串 @"2010-11-12" 之间的天数

发布于 2024-09-30 06:54:04 字数 265 浏览 1 评论 0 原文

我需要一个接收 [NSDate date] 和字符串 @"2010-11-12" 并返回这两个日期之间的天数的函数。

更多解释: 我需要在我的 NSUserdefaults 中以 @"2010-11-12" 格式存储来自服务器的日期。该日期的含义是 iPhone 应用程序中某个功能的过期日期。每次我按下此功能的按钮时,我都需要检查当前时间->[NSDate date] 和@“2010-11-12”之间的天数差异是否大于 0。这意味着该功能是禁用。

这让我发疯,也许这很简单。

I need a function which receives [NSDate date] and a string @"2010-11-12" and returns the amount of days between those two dates.

More explanation:
I need to store a date from a server in the format @"2010-11-12" in my NSUserdefaults. The meaning of this date is the expireDate of a feature in an iPhone App. Every time I press on a button for this feature I need to check if the difference in days between the current time->[NSDate date] and @"2010-11-12" is greater than 0. That means that the feature is disabled.

It's making me crazy, maybe it's dead simple.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

是伱的 2024-10-07 06:54:04

使用 NSDateFormatter 将字符串转换为 NSDate - 然后比较日期对象。

Use an NSDateFormatter to convert the string to an NSDate - then compare the date objects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文