获取当前日期时间
代码如下
function getDatetime() { var d = new Date(); var year = d.getFullYear(); var month = change(d.getMonth() + 1); var day = change(d.getDate()); var hour = change(d.getHours()); var minute = change(d.getMinutes()); var second = change(d.getSeconds()); function change(t) { if (t < 10) { return "0" + t; } else { return t; } } var time = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second; return time; } console.log(getDatetime()); // 执行结果 // 2019-06-26 23:35:16
比Python 麻烦一些,记录下方便以后使用