Re: NSDate without time component
Re: NSDate without time component
- Subject: Re: NSDate without time component
- From: Ricky Sharp <email@hidden>
- Date: Sun, 27 Nov 2005 09:38:04 -0600
On Nov 27, 2005, at 12:33 AM, Jason Wiggins wrote:
I'm a newbie and have checked out the archives but I may not be
searching for the right thing. Any help would be grateful.
What I'm doing is using an NSDatePicker to return an instance of
NSDate. All I want from this NSDate is the date, not the time
component. Or if possible, when NSDatePicker returns the NSDate,
the time is set to 00:00 UTC. Is this possible?
I would have assumed that calling setDatePickerElements: and leaving
out the ability the edit time values would normalize the time to
something sane.
If there's no way of telling the picker to normalize the time for
you, you could try using NSDateComponents and NSCalendar:
NSDate* theDate = <your picker date>
unsigned theUnitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |
NSDayCalendarUnit;
NSCalendar* theCalendar = [NSCalendar currentCalendar];
NSDateComponents* theComps = [theCalendar components:theUnitFlags
fromDate:date];
[theComps setHour:0];
[theComps setMinute:0];
[theComps setSecond:0];
NSDate* theNormalizedDate = [theCalendar dateFromComponents:theComps];
Note that you'll probably also have to play around with the time zone
(see NSCalendar's setTimeZone:)
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden