There is a whole guide to programming date and time. Here is a section that gives you a hint on what to do.
Here, where the sample code arises from another question.
Try and write something based on this, and then come back if you have specific questions.
Edit
Good. This is how I write the code in it in the most basic form.
First, I would expand NSDate.
Header file:
// NSDate+ADNExtensions.h #import <Cocoa/Cocoa.h> @interface NSDate (ADNExtensions) - (NSInteger)numberOfDaysUntil:(NSDate *)aDate; @end
Implementation File:
// NSDate+ADNExtensions.m
This is very crude code. Error checking or verifying that the second date is later than the first.
And then I will use it like this (works in a 64-bit environment with garbage):
NSDate *startDate = [NSDate dateWithString:@"2010-11-01 00:00:00 +0000"]; NSDate *endDate = [NSDate dateWithString:@"2010-11-02 00:00:00 +0000"]; NSInteger difference = [startDate numberOfDaysUntil:endDate]; NSLog(@"Diff = %ld", difference);
This is such a shame because you would have learned a lot more by posting your code and incorrect exits and getting more specific help. But if you just want to be a programmer for cutting and pasting; take this code and good luck to you.
Abizern Jan 01 2018-10-01T00: 00Z
source share