我无法理解时区,似乎无法解决它。
用户应输入警报响起的时间。因此,他们在澳大利亚悉尼时区选择周日早上 6:00(使用 pickerView)。
然后,当他们的设备将时区更改为美国洛杉矶时,警报仍应在洛杉矶时间早上 6:00 响起(现在是悉尼时间凌晨 1:00 或其他时间)。
设置通知:
UILocalNotification *localNotification;
[localNotification setTimeZone:[NSTimeZone localTimeZone]];
读取通知以显示在 TableView 中:
NSDate *fd = <the firedate of the scheduled notification>
NSDateFormatter* df_local = [[[NSDateFormatter alloc] init] autorelease];
//[df_local setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
[df_local setTimeZone:[NSTimeZone localTimeZone]];
[df_local setDateFormat:@"hh:mm"];
NSString* ts_local_string = [df_local stringFromDate:fd];
使用该代码,我将悉尼的时间设置为上午 6:00,但在洛杉矶查看时,时间现在是下午 1:00。
在设置 UILocalNotification 时我应该将时区设置为什么,以及在阅读通知时我应该将时区设置为什么,以便在悉尼和洛杉矶查看时,时间都是当地时间上午 6:00。
谢谢