如何比较iOS中的系统日期和UIDatePicker日期?
How to compare system date with UIDatePicker's date in iOS?
通过我的应用程序,用户可以在餐厅订购特定的食品。问题是,如果用户想要订购特定的产品,他可以给餐厅至少 6 小时的时间来提供 product.For 示例你是用户,现在时间是 12:00pm..在应用程序中,如果用户 selects 在 [=] 之前,用户可以 select 通过 UIDatepicker.Here 交付时间18=],一个警报视图将生成消息 "please give 6hrs time for your order"。这里我必须比较系统时间和 UIDatepickers time.I 找到一种方法,但它没有用。
if ([self.datePicker.date compare:currentdate] == NSOrderedDescending){
NSLog(@"Descending");
}
请帮助我...提前致谢
使用这个
if ([[NSDate date] isEqualToDate: currentdate) {
NSLog(@"currentDate is equal to currentdate");
}
或者你可以通过
比较选择的时间
NSDate *date1 = [NSDate date];
NSDate *date2 = datePicker.date;
NSTimeInterval elapsed = [date1 timeIntervalSinceDate:date2];
您还可以在 6 小时后设置日期选择器的最短时间
NSDate *mydate = [NSDate date];
NSTimeInterval secondsInSixHours = 6 * 60 * 60;
NSDate *dateSixHoursAhead = [mydate dateByAddingTimeInterval:secondsInSixHours];
[datePicker setMinimumDate:dateSixHoursAhead];
你实际上是在寻找时差,这里是代码:
NSLog(@"please give %@fhrs time for your order",[self.datePicker.date timeIntervalSinceDate:[NSDate date]]);
使用这个方法。比较两个日期的最佳方式:
- (void)pickerDateIsSmallerThanCurrent:(NSDate *)checkDate
{
NSDate* enddate = checkDate;
NSDate* currentdate = [NSDate date];
NSTimeInterval distanceBetweenDates = [enddate timeIntervalSinceDate:currentdate];
double secondsInMinute = 60;
NSInteger secondsBetweenDates = distanceBetweenDates / secondsInMinute;
if (secondsBetweenDates == 0)
//both dates are equal
else if (secondsBetweenDates < 0)
//selected date is smaller than current date
else
//selected date is greater than current date
}
通过我的应用程序,用户可以在餐厅订购特定的食品。问题是,如果用户想要订购特定的产品,他可以给餐厅至少 6 小时的时间来提供 product.For 示例你是用户,现在时间是 12:00pm..在应用程序中,如果用户 selects 在 [=] 之前,用户可以 select 通过 UIDatepicker.Here 交付时间18=],一个警报视图将生成消息 "please give 6hrs time for your order"。这里我必须比较系统时间和 UIDatepickers time.I 找到一种方法,但它没有用。
if ([self.datePicker.date compare:currentdate] == NSOrderedDescending){
NSLog(@"Descending");
}
请帮助我...提前致谢
使用这个
if ([[NSDate date] isEqualToDate: currentdate) {
NSLog(@"currentDate is equal to currentdate");
}
或者你可以通过
比较选择的时间NSDate *date1 = [NSDate date];
NSDate *date2 = datePicker.date;
NSTimeInterval elapsed = [date1 timeIntervalSinceDate:date2];
您还可以在 6 小时后设置日期选择器的最短时间
NSDate *mydate = [NSDate date];
NSTimeInterval secondsInSixHours = 6 * 60 * 60;
NSDate *dateSixHoursAhead = [mydate dateByAddingTimeInterval:secondsInSixHours];
[datePicker setMinimumDate:dateSixHoursAhead];
你实际上是在寻找时差,这里是代码:
NSLog(@"please give %@fhrs time for your order",[self.datePicker.date timeIntervalSinceDate:[NSDate date]]);
使用这个方法。比较两个日期的最佳方式:
- (void)pickerDateIsSmallerThanCurrent:(NSDate *)checkDate
{
NSDate* enddate = checkDate;
NSDate* currentdate = [NSDate date];
NSTimeInterval distanceBetweenDates = [enddate timeIntervalSinceDate:currentdate];
double secondsInMinute = 60;
NSInteger secondsBetweenDates = distanceBetweenDates / secondsInMinute;
if (secondsBetweenDates == 0)
//both dates are equal
else if (secondsBetweenDates < 0)
//selected date is smaller than current date
else
//selected date is greater than current date
}