Hi,
I was created the NSDate using NSCalendar with local time zone(Sydney/Australia), but it returns wrong date
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:3];
[comps setMonth:10];
[comps setYear:2019];
[comps setHour:23];
[comps setMinute:00];
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:comps];
NSCalendar *calendar =[NSCalendar currentCalendar];
calendar.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:([[NSTimeZone localTimeZone] secondsFromGMT])];
NSDate *date1 = [calendar dateFromComponents: comps];
NSCalendar *geoCalender = [[NSCalendar alloc]initWithCalendarIdentifier:@"gregorian"];
geoCalender.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:([[NSTimeZone localTimeZone] secondsFromGMT])];
NSDate *geoDate = [geoCalender dateFromComponents: comps];
NSLog(@"date: %@", date);
NSLog(@"date: %@", date1);
NSLog(@"date: %@", geoDate);
NSDateComponents *comps1 = [[NSDateComponents alloc] init];
[comps1 setDay:7];
[comps1 setMonth:10];
[comps1 setYear:2019];
[comps1 setHour:23];
[comps1 setMinute:00];
NSDate *date2 = [[NSCalendar currentCalendar] dateFromComponents:comps1];
NSDate *date3 = [calendar dateFromComponents: comps1];
NSDate *geoDate1 = [geoCalender dateFromComponents: comps1];
NSLog(@"date: %@", date2);
NSLog(@"date: %@", date3);
NSLog(@"date: %@", geoDate1);
In the above code snippet return the output dates as follow
2019-12-06 20:27:18.705789+1100 SampleiOS[78970:498109] date: Thu Oct 3 23:00:00 2019
2019-12-06 20:27:18.706128+1100 SampleiOS[78970:498109] date: Thu Oct 3 22:00:00 2019
2019-12-06 20:27:18.706467+1100 SampleiOS[78970:498109] date: Thu Oct 3 22:00:00 2019
2019-12-06 20:27:18.706831+1100 SampleiOS[78970:498109] date: Mon Oct 7 23:00:00 2019
2019-12-06 20:27:18.707043+1100 SampleiOS[78970:498109] date: Mon Oct 7 23:00:00 2019
2019-12-06 20:27:18.707201+1100 SampleiOS[78970:498109] date: Mon Oct 7 23:00:00 2019
Can you please explain which creation of NSDate as correct?