美文网首页
iOS swift时间戳转日期字符串

iOS swift时间戳转日期字符串

作者: L千载难逢 | 来源:发表于2020-04-29 11:47 被阅读0次

注意点:format格式里面的年份最好写成小写格式,例如yyyy-MM-dd HH:mm:ss,因为大写格式在12月31号转化可能会出问题

//时间戳转日期

func timeFormat(_tt:Int,format:String)->String{

    if tt<=0{return"--"}

    let date  =  Date.init(timeIntervalSince1970:TimeInterval(tt))

    let formatter =DateFormatter()

    formatter.dateFormat= format

    return formatter.string(from: date)

}

相关文章

网友评论

      本文标题:iOS swift时间戳转日期字符串

      本文链接:https://www.haomeiwen.com/subject/rrjgwhtx.html