格式化后的指定格式的日期和時間,封裝一個函式
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()));
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/166510.html
標籤:JavaScript
上一篇:探索 Reflect.apply 與 Function.prototype.apply 的區別
下一篇:js 報錯 Uncaught TypeError: Cannot read property 'trim' of undefined
