2

Right now I set an NSDate object like so:

func userSelectedDate(selectedDate : NSDate) {
    let formatter = NSDateFormatter()
    formatter.dateFormat = "dd-MM-yyyy"
    let dateString = formatter.stringFromDate(selectedDate)
}

I always want to use midnight though. How do I force the usage of a certain time?

Rutger Huijsmans
  • 2,330
  • 2
  • 30
  • 67

2 Answers2

2
let calendar = NSCalendar.currentCalendar()
let dateAtMidnight = calendar.startOfDayForDate(NSDate())
Luca Rocchi
  • 6,272
  • 1
  • 23
  • 23
0

There's an app method for that

let startOfSelectedDate = NSCalendar.currentCalendar().startOfDayForDate(selectedDate)
vadian
  • 274,689
  • 30
  • 353
  • 361