iosswiftdatensdate

Swift - Get local date and time


How can I get local date and time in Swift?

let last_login = String(NSDate.date())

Solution

  • I already found the answer.

    let dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "MM-dd-yyyy HH:mm"
    let dateInFormat = dateFormatter.stringFromDate(NSDate())