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:<rsharp...>
Instant Interactive(tm)
http://www.instantinteractive.com