Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何从nsdate中删除第二个_Iphone_Nsdate_Nsdateformatter - Fatal编程技术网

Iphone 如何从nsdate中删除第二个

Iphone 如何从nsdate中删除第二个,iphone,nsdate,nsdateformatter,Iphone,Nsdate,Nsdateformatter,我正在处理本地通知。但是,虽然我设置了通知的时间,但是它也考虑了第二。 这是我设定时间的代码 NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"HH:mm"]; [tfTime setText:[NSString stringWithFormat:@"%@",[df stringFromDate:datePicker.date]]]; selectedDateTime =

我正在处理本地通知。但是,虽然我设置了通知的时间,但是它也考虑了第二。 这是我设定时间的代码

NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"HH:mm"];

    [tfTime setText:[NSString stringWithFormat:@"%@",[df stringFromDate:datePicker.date]]];
    selectedDateTime = [datePicker date];
我希望通知时间是四舍五入的,没有秒

    UILocalNotification *notification = [[UILocalNotification alloc] init];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    //[dateFormat setDateFormat:@"dd-MM-yyyy"];

    //NSDate *notificationDate = [dateFormat dateFromString:strRemindMeBefore];
    notification.fireDate = selectedDateTime;
    notification.alertBody = tvMessage.text;
    notification.timeZone = [NSTimeZone defaultTimeZone];
    notification.soundName = UILocalNotificationDefaultSoundName;
    notification.applicationIconBadgeNumber = 1;

    [[UIApplication sharedApplication] scheduleLocalNotification:notification];

您可以做的是使用NSDATE组件,如下所示,并将秒数设置为00,这可能会有帮助。。。下面是一个示例代码,您可以在其中手动设置所有组件

希望这有帮助

NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
[comps setDay:1];
[comps setMonth:1];
[comps setYear:2013];
[comps setHour:10];
[comps setMinute:10];
/// You can set this component as 00
[comps setSecond:00];
localNotif.fireDate = [[NSCalendar currentCalendar] dateFromComponents:comps];

您可以做的是使用NSDATE组件,如下所示,并将秒数设置为00,这可能会有帮助。。。下面是一个示例代码,您可以在其中手动设置所有组件

希望这有帮助

NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
[comps setDay:1];
[comps setMonth:1];
[comps setYear:2013];
[comps setHour:10];
[comps setMinute:10];
/// You can set this component as 00
[comps setSecond:00];
localNotif.fireDate = [[NSCalendar currentCalendar] dateFromComponents:comps];
将日期“舍入”为分钟或其他单位的方便方法是
rangeOfUnit:…
NSCalendar
的方法

NSDate *selectedDateTime = [datePicker date];
NSDate *roundedDate;
NSCalendar *cal = [NSCalendar currentCalendar];
[cal rangeOfUnit:NSCalendarUnitMinute startDate:&roundedDate interval:NULL forDate:selectedDateTime];
// …
notification.fireDate = roundedDate;
将日期“舍入”为分钟或其他单位的方便方法是
rangeOfUnit:…
NSCalendar
的方法

NSDate *selectedDateTime = [datePicker date];
NSDate *roundedDate;
NSCalendar *cal = [NSCalendar currentCalendar];
[cal rangeOfUnit:NSCalendarUnitMinute startDate:&roundedDate interval:NULL forDate:selectedDateTime];
// …
notification.fireDate = roundedDate;

通知的代码在哪里?通知的代码在哪里?哇,真是个不错的解决方案!不幸的是,在我看来,这些文档在这一点上有点混乱。哇,真是个不错的解决方案!不幸的是,在我看来,这些文件在这一点上有点混乱。