js怎么把时间转换成年月日时分秒的形式

JavaScript014

js怎么把时间转换成年月日时分秒的形式,第1张

需要准备的材料分别有:电脑、html编辑器、浏览器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<script>标签,输入js代码:var a = 1562060142000document.body.innerText = new Date(a)。

3、浏览器运行index.html页面,此时时间被转化为年月日时分秒打印出来了。

需要准备的材料分别有:电脑、html编辑器、浏览器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<script>标签,输入js代码:

var a = new Date()document.body.innerHTML

= '时:' + a.getHours() + '<br/>分:' + a.getMinutes() + '<br/>秒:' + a.getSeconds()

3、浏览器运行index.html页面,此时当前时间的时分秒都被js获取并打印了出来。

仅针对这个问题来说,不需要那么大量的代码即可完成 方案1(适用于中国标准时间): var date = new Date(+new Date()+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'')方案2(只用于题目中所述的格式转换)