Hi Everyone,
I have a question about the comps setHour: part of my code.
In the code below I have 4 to represent 4am, however when I run the code I get an hour offset and the result of 3am… I have put the output below the code.
Can anyone help me understand this offset
I did read in a C programming book that setHour goes from 0 - 23.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear: 1976];
[comps setMonth: 11];
[comps setDay: 25];
[comps setHour: 4];
[comps setMinute: 45];
[comps setSecond: 0];
NSCalendar *g = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *dateOfBirth = [g dateFromComponents:comps];
NSDate *seconds = [[NSDate alloc] init];
double s = [seconds timeIntervalSinceDate:dateOfBirth]; //time in Seconds
NSLog(@"My date of birth is: %@ \n\n", dateOfBirth);
NSLog(@"Time difference between now and then in seconds is: %f", s);
}
return 0;
}
Output:
2014-10-10 22:04:07.432 Time_After_Time[1473:303] My date of birth is: 1976-11-25 03:45:00 +0000
2014-10-10 22:04:07.433 Time_After_Time[1473:303] Time difference between now and then in seconds is: 1195229947.428336
Program ended with exit code: 0
Cheers
JP