I'm trying to set time on a NSDatePicker
according to a certain offset that I have in milliseconds. When I set the time, the value that I see is off and I can't figure out why.
Here is the code I use to set the picker:
- (void)setDatePicker{
int targetmillisondsFromMidnight = [self.schedule.targetHour intValue]; //Value is: 61680000 milliseconds whis is equal to 17:08 UTC (or 19:08 in my local time);
NSDate* todayMidnight = [NSCalendar.currentCalendar startOfDayForDate:[NSDate new]];
NSTimeZone* timezone = [NSTimeZone localTimeZone]; //Value is: Local Time Zone (Asia/Jerusalem (GMT+2) offset 7200)
NSInteger seconds = [timezone secondsFromGMT]; //Value is: 7200
todayMidnight = [todayMidnight dateByAddingTimeInterval:seconds]; // Value is: 2019-12-25 00:00:00 UTC
NSDate* scheduleDate = [NSDate dateWithTimeInterval:targetmillisondsFromMidnight/1000 sinceDate:todayMidnight]; //Value is: 2019-12-25 17:08:00 UTC
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
NSDateComponents *components = [calendar components:(NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:scheduleDate];
[self.datePicker setDate:[calendar dateFromComponents:components] animated:YES];
}
I stop with a breakpoint at the last command in the function and I print some values, the outputs that I get are:
po [components hour] = 17
po [components minute] = 8
po [calendar dateFromComponents:components] = 001-01-01 17:08:00 +0000
So from my understanding the date is set with 17:08. What I expect to see on the time picker is 19:08, however what I see is 19:28. I can't figure out where those 20 minutes are coming from.