我想知道如何创建设置为年底的NSDate
。即2013年, 我发现了一种方法,你可以通过增加秒数来获得自1970年以来的时间。我没有看到这个工作,因为秒数将不得不在闰年。iPhone有没有办法从NSDateComponents获得nsdate
我发现以下代码将NSDateComponents
设置为年底。
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear:2012];
[comps setMonth:12];
[comps setDay:11];
[comps setHour:0];
[comps setMinute:0];
[comps setSecond:0];
有没有办法从此得到NSDate
? 我想要做的是通过使用
NSDateComponents *timeDifference = [[NSCalendar currentCalendar]
components: NSMonthCalendarUnit| NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:[NSDate date] toDate:comps options:0];
这对于结束日期需要NSDate
得到,直到今年年底的时间量。