0
我必须在当地时间下午6点设置UIAlertNotification。时间设定在上午11点,因为我现在所处的当地时区是格林威治标准时间+6:00,因此时间为下午18点。但是,在不同的时区它会有所不同。我希望在任何时区下午六点。任何人都可以帮助我吗?谢谢。关于NSDateComponents TimeZone
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小时(自格林威治标准时间+7 - 日光以来),并使其18点。
我想我做的一切都是对的。我已添加完整的代码。请让我知道我犯了什么错误。 – Ahsan 2012-03-22 00:44:58
当你说“当我打印日期”时,你在说什么日期?另外,你没有设置通知的'timeZone'属性。 – yuji 2012-03-22 08:06:58