This code
NSCalendar *calendar =[NSCalendar currentCalendar]; [gregorian setTimeZone:tz]; NSLog(@"%@", [gregorian timeZone]); NSDateComponents *comp = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit) fromDate:[NSDate date]]; [comp setDay:info.day]; [comp setMonth:info.month]; [comp setYear:info.year]; [comp setHour:info.hour]; [comp setMinute:info.minute]; [comp setSecond:info.second]; [comp setTimeZone:tz]; NSLog(@"%@", [comp timeZone]); NSLog(@"%@", [gregorian dateFromComponents:comp]);
shows the following in the console:
Europe/Moscow (MSKS) offset 14400 (Daylight) Europe/Moscow (MSKS) offset 14400 (Daylight) 2011-08-31 20:00:00 +0000
So, the time zone for the calendar and components is correct, but [gregorian dateFromComponents:comp] returns the NSDate with the wrong time zone (GMT).
What do I need to fix the correct time zone?
ios iphone nscalendar nstimezone
Mitry Sep 06 2018-11-11T00: 00Z
source share