I have two datepickers that gives me a startTime and an endTime. according to this code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.timeZone=[NSTimeZone defaultTimeZone];
dateFormatter.timeStyle=NSDateFormatterShortStyle;
dateFormatter.dateStyle=NSDateFormatterShortStyle;
NSString *dateTimeString=[dateFormatter stringFromDate:startTime.date];
NSLog(@"Start time is %@",dateTimeString);
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc]init];
dateFormatter2.timeZone=[NSTimeZone defaultTimeZone];
dateFormatter2.timeStyle=NSDateFormatterShortStyle;
dateFormatter2.dateStyle=NSDateFormatterShortStyle;
NSString *dateTimeString2=[dateFormatter2 stringFromDate:endTime.date];
NSLog(@"End time is %@",dateTimeString2);
in my .h
@property (weak, nonatomic) IBOutlet UIDatePicker *startTime;
@property (weak, nonatomic) IBOutlet UIDatePicker *endTime;
and I have this code that let me compare between the giving time and current time. What is the best way to test it as I need to you use it in the background.
if ([[NSDate date] isEqualToDate:startTime.date]) {
NSLog(@"currentDate is equal to startTime");
}
if ([[NSDate date] isEqualToDate:endTime.date]) {
NSLog(@"currentDate is equal to endTime");
}
I need to choose between that code or this one. so would NSLog
work ok here?
- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate
if([startTime.date timeIntervalSinceDate:[NSDate date]] > 0)
{
//start time greater than today
}
else if([startTime.date timeIntervalSinceDate:[NSDate date]] < 0)
{
//start time less than today
}
else
{
//both dates are equal
}
Thanks