300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > js把中国标准时间转化为YY-MM-DD hh:mm:ss

js把中国标准时间转化为YY-MM-DD hh:mm:ss

时间:2019-04-23 18:24:30

相关推荐

js把中国标准时间转化为YY-MM-DD hh:mm:ss

下列方法可以直接把中国标准时间转化为YY-MM-DD hh:mm:ss的时间,便于传值。

function formatDate(d){var date = new Date(d);var YY = date.getFullYear() + "-";var MM =(date.getMonth() + 1 < 10? "0" + (date.getMonth() + 1): date.getMonth() + 1) + "-";var DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();var hh =(date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";var mm =(date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +":";var ss =date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();return YY + MM + DD + " " + hh + mm + ss;}let time = new Date();let res = formatDate(time);console.log(res) //当前时间 YY-MM-DD hh:mm:ss

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。