美文网首页
微信小程序--时间戳使用

微信小程序--时间戳使用

作者: 北冥有鱼_425c | 来源:发表于2019-11-11 17:19 被阅读0次

时间戳

备注:

​ 时间戳包括10位和13位两种,小程序中默认生成的时间戳是13位的。两者的区别是精度不同,13位精确到毫秒,10位精确到秒。实际上,13位时间戳只是比10位的末尾多了000,如果想要转化只要乘除1000即可。

// 将时间戳( times )转换成指定日期格式
formateTime( times ) {
    let date = new Date( times*1000 )
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    let dates = date.getDate()
    return year + "." + month + "." + dates
}

相关文章

网友评论

      本文标题:微信小程序--时间戳使用

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