时间戳

  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)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容