JS基础语法---Date对象---格式化日期
格式化后的指定格式的日期和时间,封装一个函数
function getDate() { var dt = new Date(); var year = dt.getFullYear(); var month = dt.getMonth(); var date = dt.getDate(); var hour = dt.getHours(); var minute = dt.getMinutes(); var second = dt.getSeconds(); month = month < 10 ? "0" + month : month; date = date < 10 ? "0" + date : date; hour = hour < 10 ? "0" + hour : hour; minute = minute < 10 ? "0" + hour : hour; second = second < 10 ? "0" + second : second; return year + "年" + month + "月" + date + "日" + hour + ":" + minute + ":" + second; } console.log(getDate(new Date()));
你好,我是Jane,如果万幸对您有用,请帮忙点下推荐,谢谢啦~另外,咱们闪存见哦~