I frequently use the NSDate compare method – but I want to consider two dates similar if they are equal in year, month, day. I have made a procesure called “cleanDate” to remove the hour part before I compare.
-(NSDate*)cleanDate:(NSDate*)date {
NSCalendarUnit unitflags;
NSDateComponents *component;
NSCalendar *calendar;
calendar=[[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]autorelease];
unitflags=NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
component=[calendar components:unitflags fromDate:date];
return [calendar dateFromComponents:component]; //Dato uten klokke
}
But my dates come out as:
2011-10-28 22:00:00
and some dates as:
2011-10-28 23:00:00
I want the hour part to be similar, e.g. 00:00.
Whats wrong? Does it have something to do with daylight saving time? Other? Thanks.
Seems like this is a Time Zone issue…
I thought NSLog would default to the local time zone – but it seems to default to GMT…
… so my original cleanDate actually seems to do what I want after all…