OStack程序员社区-中国程序员成长平台

标题: ios - 本地通知设置默认时间 9 :00 am for user timezone in iOS [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 08:24
标题: ios - 本地通知设置默认时间 9 :00 am for user timezone in iOS

我想为每个用户时区时间设置通知默认上午 9:00

如何为默认时间 9:00 am 创建 触发日期



Best Answer-推荐答案


你好,我知道了答案:-

NSDate *pickerDate = [NSDate date]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormatT_FORMATE_BIRTHDATE];
    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviationT_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];

关于ios - 本地通知设置默认时间 9 :00 am for user timezone in iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998833/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4