Rutger Huijsmans Rutger Huijsmans - 1 year ago 104
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?

Answer Source
let calendar = NSCalendar.currentCalendar()
let dateAtMidnight = calendar.startOfDayForDate(NSDate())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download