欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

JS中的日期和时间格式化技巧

最编程 2024-08-03 20:53:21
...
function dataTime(){ //生成当前时间 const date = new Date() let year = date.getFullYear() + '' let month = date.getMonth() + 1 + '' let day = date.getDate() + '' let hours = date.getHours() + '' let minutes = date.getMinutes() + '' let seconds = date.getSeconds() + '' return year + '-' + month.padStart(2,'0') + '-' + day.padStart(2,'0') + ' ' + hours.padStart(2,'0') + ':' + minutes.padStart(2,'0') + ':' + seconds.padStart(2,'0') }