Rutger Huijsmans Rutger Huijsmans - 6 months ago 34
Swift Question

Setting an NSDate to always use midnight

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?

let calendar = NSCalendar.currentCalendar()
let dateAtMidnight = calendar.startOfDayForDate(NSDate())