我想通过忽略秒来比较两个日期和时间。下面是我尝试但似乎不成功的代码。任何人都可以在我出错的地方帮助我或者为我提供更好的解决方案吗?感谢
-(BOOL)checkIfTimePassed{
NSDate *today = [NSDate date];
BOOL isTimePassed = [[NSCalendar currentCalendar] compareDate:today toDate:self.whenDate toUnitGranularity:NSCalendarUnitMinute] != NSOrderedAscending;
return isTimePassed;
}
答案 0 :(得分:4)
你的比较结束了。试试这个。注意参数的变化和比较。
-(BOOL)checkIfTimePassed{
NSDate *today = [NSDate date];
BOOL isTimePassed = [[NSCalendar currentCalendar] compareDate:self.whenDate toDate:today toUnitGranularity:NSCalendarUnitMinute] == NSOrderedAscending;
return isTimePassed;
}
答案 1 :(得分:0)
这似乎是现在的解决方案。如果有人变得更好,就发布它。
-(BOOL)checkIfTimePassed{
NSDate *today = [NSDate date];
NSComparisonResult result = [[NSCalendar currentCalendar] compareDate:today toDate:self.whenDate toUnitGranularity:NSCalendarUnitMinute];
if(result==NSOrderedAscending){
NSLog(@"today is less");
return NO;
}
else if(result==NSOrderedDescending)
{
NSLog(@"newDate is less");
return YES;
}
else
{
NSLog(@"Both dates are same");
return NO;
}
}
答案 2 :(得分:0)
Sub chart_to_Xcl()
Dim ppt As PowerPoint.Application
Set ppt = New PowerPoint.Application
ppt.Visible = msoCTrue
Dim ppres As PowerPoint.Presentation
Set ppres = ppt.Presentations.Add
Dim pSlide As PowerPoint.Slide
Set pSlide = ppres.Slides.Add(1, ppLayoutTitleOnly)
Dim ws As Worksheet
Dim myChart As ChartObject
Dim j As Long
j = 0
For Each ws In Worksheets
ws.Select
For Each myChart In ActiveSheet.ChartObjects
j = j + 1
Next
For Each myChart In ActiveSheet.ChartObjects
myChart.Select
myChart.Copy
pSlide.Shapes.PasteSpecial link:=msoCTrue
Set pSlide = ppres.Slides.Add(ppres.Slides.Count + 1, ppLayoutTitleOnly)
Next
Next
End Sub
Sub chart_to_Xcl()
Dim ppt As PowerPoint.Application
Set ppt = New PowerPoint.Application
ppt.Visible = msoCTrue
Dim ppres As PowerPoint.Presentation
Set ppres = ppt.Presentations.Add
Dim pSlide As PowerPoint.Slide
Set pSlide = ppres.Slides.Add(1, ppLayoutTitleOnly)
Dim ws As Worksheet
Dim myChart As ChartObject
Dim j As Long
j = 0
For Each ws In Worksheets
ws.Select
For Each myChart In ActiveSheet.ChartObjects
j = j + 1
Next
For Each myChart In ActiveSheet.ChartObjects
myChart.Select
myChart.Copy
pSlide.Shapes.PasteSpecial link:=msoCTrue
Set pSlide = ppres.Slides.Add(ppres.Slides.Count + 1, ppLayoutTitleOnly)
Next
Next
End Sub
Sub chart_to_Xcl()
Dim ppt As PowerPoint.Application
Set ppt = New PowerPoint.Application
ppt.Visible = msoCTrue
Dim ppres As PowerPoint.Presentation
Set ppres = ppt.Presentations.Add
Dim pSlide As PowerPoint.Slide
Set pSlide = ppres.Slides.Add(1, ppLayoutTitleOnly)
Dim ws As Worksheet
Dim myChart As ChartObject
Dim j As Long
j = 0
For Each ws In Worksheets
ws.Select
For Each myChart In ActiveSheet.ChartObjects
j = j + 1
Next
For Each myChart In ActiveSheet.ChartObjects
myChart.Select
myChart.Copy
pSlide.Shapes.PasteSpecial link:=msoCTrue
Set pSlide = ppres.Slides.Add(ppres.Slides.Count + 1, ppLayoutTitleOnly)
Next
Next
End Sub
Sub chart_to_Xcl()
Dim ppt As PowerPoint.Application
Set ppt = New PowerPoint.Application
ppt.Visible = msoCTrue
Dim ppres As PowerPoint.Presentation
Set ppres = ppt.Presentations.Add
Dim pSlide As PowerPoint.Slide
Set pSlide = ppres.Slides.Add(1, ppLayoutTitleOnly)
Dim ws As Worksheet
Dim myChart As ChartObject
Dim j As Long
j = 0
For Each ws In Worksheets
ws.Select
For Each myChart In ActiveSheet.ChartObjects
j = j + 1
Next
For Each myChart In ActiveSheet.ChartObjects
myChart.Select
myChart.Copy
pSlide.Shapes.PasteSpecial link:=msoCTrue
Set pSlide = ppres.Slides.Add(ppres.Slides.Count + 1, ppLayoutTitleOnly)
Next
Next
End Sub