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

时间:2016-07-18 08:21:09

标签: ios objective-c nsdate

我使用此

获取当前日期
 NSDate *currDate;
currDate = [NSDate date];

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

我该怎么做?

1 个答案:

答案 0 :(得分:1)

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

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);

我了解了亚洲/加尔各答"通过记录 -

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

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