Rutger Huijsmans Rutger Huijsmans - 1 month ago 5x
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())