Search code examples
swiftnsdate

Swift NSDate get current date but strip Year, Month, and Day


I am trying to get the current date using swift. I have that taken care of but it gets the year month and day and I really only want the current hour and minute. The reason being is that I am trying to later on compare a created date that only has an hour and minute. I am currently just using this

let currentDate = NSDate()

Thank you


Solution

  • let calendar = Calendar.autoupdatingCurrent
    let components = calendar.dateComponents([.hour, .minute], from: Date())
    let hour = components.hour
    let minute = components.minute