// 獲取系統(tǒng)當(dāng)前時(shí)間
let date = NSDate()
// 將時(shí)間轉(zhuǎn)化為某種格式
let dateFormatter = NSDateFormatter()
// 將時(shí)間以年月日時(shí)分秒顯示
dateFormatter.dataFormat = "yyyy-MM-dd-HH-mm-ss"
// 假設(shè)一個(gè)時(shí)間
let date1 = 2016-8-9 08:35:43
let newDate = dateFormatter.datFormString(date1)
//計(jì)算出當(dāng)前時(shí)間與傳入時(shí)間的差值(單位為秒)
let dealy = date.timeNSTimevalSinceDate(newDate)