I have to set an UIAlertNotification at 6:00 pm local time. The time is set at 11:00am and will get to 18:00 pm because the local time zone I am in right now is GMT+6:00. However, it will be different in different time zones. I want it to be 6:00pm at any time zone. Can anyone kindly help me out? Thanks.
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];
//local alert code
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];
Notes:
When I print the date, it says:
date = "2012-04-04 18:00:00 +0000";
I think it means that 11am was GMT and by adding 7 hours (since its GMT +7 - daylight) and makes it 18 pm.