利用NSDateFormatter类可以进行时间格式与时间戳之间的转化
:param: stringTime 时间为string
:returns: 返回时间戳为strings
*/
static func stringToTimeStamp(stringTime:String)->String {
var dfmatter = NSDateFormatter()
dfmatter.dateFormat="yyyy年MM月dd日"
var date = dfmatter.dateFromString(stringTime)
var dateStamp:NSTimeInterval = date!.timeIntervalSince1970
var dateSt:Int = Int(dateStamp)
print(dateSt)
return String(dateSt)
}
:param: timeStamp <#timeStamp description#> :returns: return time */ static func timeStampToString(timeStamp:String)->String { var string = NSString(string: timeStamp) var timeSta:NSTimeInterval = string.doubleValue var dfmatter = NSDateFormatter() dfmatter.dateFormat="yyyy年MM月dd日" var date = NSDate(timeIntervalSince1970: timeSta) print(dfmatter.stringFromDate(date)) return dfmatter.stringFromDate(date) }