Reputation: 20875
I want to ask 2 questions about the NSDate of iPhone application.
1) How to set the NSDate *startDay to 01-01-2010 and NSDate *endDay to 31-12-2010
2) how many day between the startDay and the endDay.
What should I do? Thank you very much.
Upvotes: 1
Views: 2392
Reputation: 4344
For handling dates with different formats you would need to use NSDateFormatter
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"mm-dd-yyyy"];
To get date with specified format
NSString *dateString = [format stringFromDate:date];
To create a date from string with specified format:
NSDate *date = [format dateFromString:dateString];
To find the difference between two dates:
NSTimeInterval interval = [endDay timeIntervalSinceDate:startDay];
timeIntervalSinceDate documentation
Upvotes: 6