My local and default time zone is GMT +5 but when I get date and time by NSDate it return me GMT date and time.
For example the code and output from my code while
Try this
- (NSDate *) GetLocalDate {
NSDateComponents *dayComponent = [[NSDateComponents alloc] init];
NSCalendar *theCalendar = [NSCalendar currentCalendar];
theCalendar.timeZone = [NSTimeZone timeZoneWithName:@"GMT"];
dayComponent = [[NSCalendar currentCalendar] components:NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
NSDate *localDate = [theCalendar dateFromComponents:dayComponent];
return localDate;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"localDate : %@",[self GetLocalDate]);
}