• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDate without time component
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSDate without time component (From: Jason Wiggins <email@hidden>)

  • Prev by Date: Re: CFSocket freezes
  • Next by Date: Re: How do I put a GIF onto an NSPasteboard?
  • Previous by thread: NSDate without time component
  • Next by thread: How to use CoreData with multiple threads and ManagedObjectContexts
  • Index(es):
    • Date
    • Thread