有人知道为什么dateTime返回的“ hh”与下面的time返回的“ hh”不同吗?
//Create new Date() Object
var dateTime = new Date();
console.log(dateTime);
//Extract Date
var date = dateTime.getDate() + "/" + (parseInt(dateTime.getMonth())+1) + "/" + dateTime.getFullYear().toString().substr(-2);
console.log(date);
//Extract Time
var time = (dateTime.getHours()) + ":" + (parseInt(dateTime.getMinutes())+1) + ":" + (parseInt(dateTime.getSeconds())+1);
console.log(time);
答案 0 :(得分:1)
好得多,非常感谢您的建议!
//Create new Date() Object
var dateTime = new Date();
console.log(dateTime);
//Extract Date
var date = dateTime.getDate() + "/" + (parseInt(dateTime.getMonth())+1) + "/" + dateTime.getFullYear().toString().substr(-2);
console.log(date);
//Extract Time
var time = (dateTime.getHours()) + ":" + dateTime.getMinutes() + ":" + dateTime.getSeconds();
console.log(time);
输出: 2019-11-21T08:26:54.781Z 19/11/11 10:26:54