現地時間の午後 6 時に UIAlertNotification を設定する必要があります。時刻は午前 11:00 に設定されており、現在のローカル タイム ゾーンは GMT+6:00 であるため、午後 18:00 になります。ただし、異なるタイムゾーンでは異なります。どの時間帯でも午後 6:00 になりたいです。誰でも親切に助けてもらえますか?ありがとう。
NSDateComponents *comps=[[[NSDateComponents alloc]init]autorelease];
[comps setYear:[year intValue]];
[comps setMonth:[month intValue]];
[comps setDay:[day intValue]];
[comps setHour:[@"11" intValue]];//6pm
[comps setMinute:0];
[comps setMinute:0];
[comps setTimeZone:[NSTimeZone localTimeZone]];
NSCalendar *cal=[[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *date1=[[cal dateFromComponents:comps]retain];
// ローカル アラート コード
NSInteger minutesAhead = 0;
NSTimeInterval seconds = (60 * minutesAhead) * -1;
NSDate *actualFireDate = [date1 dateByAddingTimeInterval:seconds];
NSMutableDictionary *dictC = [NSMutableDictionary dictionaryWithDictionary:userInfo];
[dictC setObject:date1 forKey:@"PCOriginalReminderDate"];
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = actualFireDate;
notification.alertBody = message;
notification.userInfo = dictC;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];
ノート:
日付を印刷すると、次のように表示されます。
date = "2012-04-04 18:00:00 +0000";
これは、午前 11 時が GMT であり、7 時間 (GMT +7 - 日光から) を追加することで、午後 18 時になることを意味すると思います。