title: How can I set an NSDate object to midnight?
body: <p>I have an <code>NSDate</code> object and I want to set it to an arbitrary time (say, midnight) so that I can use the <code>timeIntervalSince1970</code> function to retrieve data consistently without worrying about the time <em>when</em> the object is created.</p>
  
  <p>I've tried using an <code>NSCalendar</code> and modifying its components by using some Objective-C methods, like this:</p>
  
  <pre class="lang-swift prettyprint-override"><code>let date: NSDate = NSDate()
  let cal: NSCalendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)!
  
  let components: NSDateComponents = cal.components(NSCalendarUnit./* a unit of time */CalendarUnit, fromDate: date)
  let newDate: NSDate = cal.dateFromComponents(components)
  </code></pre>
  
  <p>The problem with the above method is that you can only set one unit of time (<code>/* a unit of time */</code>), so you could only have one of the following be accurate:</p>
  
  <ol>
  <li>Day</li>
  <li>Month</li>
  <li>Year</li>
  <li>Hours</li>
  <li>Minutes</li>
  <li>Seconds</li>
  </ol>
  
  <p>Is there a way to set hours, minutes, and seconds at the same time and retain the date (day/month/year)?</p>