【发布时间】:2013-12-11 13:59:50
【问题描述】:
我正在开发一个 iPhone 应用程序。
如何在 iPhone 中获取从当年第一个日期到当前日期的天数。
我试过这段代码: NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorianCalendar components:NSDayCalendarUnit fromDate:self toDate:aDate options:0];
return [components day];
但是当我给出的日期是:jan /01/2013 todate 是:dec/12/31 我得到了 363 天。但是我们有365天。
请帮我解决这个问题。谢谢。
【问题讨论】:
-
什么????????????当你把我搞糊涂的时候,我理解到“iPhone 中的第一个日期到当前日期”。
-
请告诉我们您已经尝试过什么以及该代码有什么问题!
-
@popeye 你有我的问题吗?
-
我的第一印象是你想知道从 x 天(2013 年 1 月 1 日)到 y 天(今天)有多少天。那是对的吗?如果是这样,请分享您的尝试,让您的问题更有意义。
-
@HAS Friend 我需要获取从当年第一个日期到当前日期的天数。我需要从当年获取当前日期总天数。