我想为每个用户的时区时间设置通知默认9:00 。
如何在默认时间上午9:00 创建开火日期。
答案 0 :(得分:1)
你好,我得到了这个答案: -
NSDate *pickerDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:DT_FORMATE_BIRTHDATE];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:DT_TIME_ZONE_GMT];
[dateFormatter setTimeZone:gmt];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSDateComponents *timeComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
fromDate:pickerDate];
[timeComponents setHour:9];
[timeComponents setMinute:00];
[timeComponents setSecond:0];
NSDate *dtFinal = [calendar dateFromComponents:timeComponents];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
NSString *fierDate = [formatter stringFromDate:dtFinal];
答案 1 :(得分:0)
This是关于本地通知的完整教程
下面是解决上面提到的时区问题。请详细查看这些时区功能,并在功能中设置适当的时区。
[NSTimeZone defaultTimeZone]
[NSTimeZone systemTimeZone]
[NSTimeZone localTimeZone]
NSTimeZone: what is the difference between localTimeZone and systemTimeZone?
答案 2 :(得分:0)
试试这段代码。
NSDate *pickerDate = [date_picker date];
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = @"Alert Body Message";
localNotification.alertAction = @"Alert Action Message";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];