将当前时间更改为印度标准时间

Change current time to Indian standard time

我正在使用这个获取当前日期

 NSDate *currDate;
currDate = [NSDate date];

但是如果用户从其他国家/地区打开我的应用程序,currDate 也应该是印度时间。

我该怎么做?

检查这是否有帮助,可能有多种方法可以解决这个问题 - 但这是可读的 -

NSDate *currentDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Kolkata"]];
NSString *indianTimeZone = [dateFormatter stringFromDate:currentDate];
NSLog(@"%@", indianTimeZone);

我通过登录了解了 "Asia/Kolkata" -

NSLog(@"%@", [NSTimeZone knownTimeZoneNames]);

此外,结帐 this answer,我喜欢这种方法。