javascript中日期的最简单格式化

// 假设要转换的日期数据来源是date(一个timestamp)
let date = Date.now()
// 1574141546000

let strDate = (new Date(date)).toLocaleDateString()
console.log(strDate)
// 打印结果:"2019/11/19"

let strTime = (new Date(date)).toLocaleTimeString()
console.log(strTime)
// 打印结果:"13:32:26"

let strDateTime = (new Date(date)).toLocaleString()
console.log(strDateTime)
// 打印结果:"2019/11/19 13:32:26"

将js中Date对象转为原始值:

(new Date()).valueOf()
// 1574142148228

posted on 2019-11-19 13:40  CoderMonkey  阅读(381)  评论(0)    收藏  举报

导航