How to get current date in swift 3?

Mohsin Qureshi picture Mohsin Qureshi · Sep 20, 2016 · Viewed 13.4k times · Source

I want to get current date and time zone of user in Swift 3. I tried in Swift 2.2 following code :

static var localTimeZoneAbbreviation: String { return NSTimeZone.localTimeZone().abbreviation!}

Answer

Nirav D picture Nirav D · Sep 20, 2016

For getting abbreviation from NSTimeZone.

static var localTimeZoneAbbreviation: String { return  NSTimeZone.local.abbreviation(for: Date())! }

For getting current Date.

let currentDate = Date()