I’m trying to figure out how to create a NSDate that is set to the end of the year. ie 2013,
I found a method that you can get the time since 1970 by adding the amount of seconds. I don’t see this working because cal the seconds would have to take in leap years.
I found the following code to set a NSDateComponents to the end of the year.
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear:2012];
[comps setMonth:12];
[comps setDay:11];
[comps setHour:0];
[comps setMinute:0];
[comps setSecond:0];
is there a way to get a NSDate from this?
What I’m trying to do is get the amount of time until the end of the year by using
NSDateComponents *timeDifference = [[NSCalendar currentCalendar]
components: NSMonthCalendarUnit| NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:[NSDate date] toDate:comps options:0];
which needs a NSDate for the end date.
Yes, there is.
Use
You can change the calender identifier as per your requirement.
Please refer this link for details.