时间戳

  1. 获取当前时间的时间戳
//获取当前时间
let now = Date.now()
//获取时间戳
let timeInterval:TimeInterval = now.timeIntervalSince1970
let timeStamp = Int(timeInterval)
  1. 获取指定时间的时间戳
//指定时间
let location = NSLocale(localeIdentifier: "zh-CN")
let timeString = "20170908211500"
let dformatter = DateFormatter()
dformatter.locale = location as Locale!
dformatter.dateFormat = "yyyyMMddHHmmss"
//转为date
let date:Date = dformatter.date(from: timeString)!
//转换为时间戳
let timeInterval:TimeInterval = date.timeIntervalSince1970
let timeStamp = Int(timeInterval)

你可能感兴趣的:(时间戳)