如何将日期组件添加到具有时间格式的NSDate

时间:2012-02-01 10:38:50

标签: iphone

请参阅以下代码

        NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
        [outputFormatter setDateFormat:@"h:mm a"];
        NSDate *dat=pickerView.date;
        NSString *timerString=[outputFormatter stringFromDate:dat];

        [startTimer setTitle:timerString forState:UIControlStateNormal]; 
        timeString=timerString;
        [self updatePrayerTimigs];
        //dat=[NSDate dateWithTimeIntervalSinceNow:20];
        UILocalNotification *local=[[[UILocalNotification alloc]init] autorelease];
        UIApplication *app=[UIApplication sharedApplication];
        if(local){
            local.fireDate=dat;
            local.timeZone=[NSTimeZone defaultTimeZone];
            //local.repeatInterval=0;
            local.alertBody=@"Hello";
            local.repeatInterval=NSMinuteCalendarUnit;
            [app scheduleLocalNotification:local];
            [app presentLocalNotificationNow:local];
        }// end of the if

我只从UIDatePicker中选择时间(小时,分钟),所以我可以触发通知,所以我决定从UIDatePicker中选择将当前日期添加到上面的NSDate,请帮助我该怎么做

1 个答案:

答案 0 :(得分:0)

尝试使用此格式化日期

 NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];

 [outputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];