NSDate without time portion
NSDate without time portion
- Subject: NSDate without time portion
- From: Brian Bruinewoud <email@hidden>
- Date: Mon, 4 Jan 2010 21:26:04 +1100
Hi All,
What's the best way to get an NSDate object for 'today' such that the time is 00:00:00 (or any other constant).
I not interested in the time, I only care about the year-month-day, but I do need the the hours-minutes-seconds to be the same on all dates so that I can compare the dates.
Currently I do this:
NSDateFormatter *dateFmter = [[NSDateFormatter alloc] init];
[dateFmter setTimeStyle:NSDateFormatterNoStyle];
[dateFmter setDateStyle:NSDateFormatterMediumStyle];
NSString dateText = [ dateFmter stringFromDate: self.now ]; // !! !! I need dateText anyway
self.now = [ dateFmter dateFromString: dateText ]; // !! truncate time to 00:00:00
But this seems ugly, cumbersome and inefficient.
The other option might be to use NSDate, NSCalendar and NSDateComponents, but that seems to be even more ugly and cumbersome and probably more inefficient.
Something like NSDate dateForTodayWithNoTimeComponentPleaseKTHXBAI would be good.
Regards,
Brian.
(Apologies for gratuitous LOLspeak)_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden