如何在swift 3中获取当前日期?

时间:2016-09-20 06:04:16

标签: ios swift nsdate swift3 nstimezone

我想在Swift 3中获取用户的当前日期和时区。我在Swift 2.2中尝试了以下代码:

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

1 个答案:

答案 0 :(得分:11)

abbreviation获取NSTimeZone

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

获取最新Date

let currentDate = Date()