iosswiftnsdatensdatepicker

Set NSDate 0 seconds in swift


I'm trying to get NSDate from UIDatePicker, but it constantly returns me a date time with trailing 20 seconds. How can I manually set NSDate's second to zero in swift?


Solution

  • From this answer in Swift:

    var date = NSDate();
    let timeInterval = floor(date .timeIntervalSinceReferenceDate() / 60.0) * 60.0
    date = NSDate(timeIntervalSinceReferenceDate: timeInterval)