首页 > 编程知识 正文

js时间年月日时分秒,时间显示月日时分

时间:2023-05-05 13:48:47 阅读:259087 作者:2899

直接拷贝函数即可使用

function nowTime() {//获取当前时间 let now= new Date(); let _month = ( 10 > (now.getMonth()+1) ) ? '0' + (now.getMonth()+1) : now.getMonth()+1; let _day = ( 10 > now.getDate() ) ? '0' + now.getDate() : now.getDate(); let _hour = ( 10 > now.getHours() ) ? '0' + now.getHours() : now.getHours(); let _minute = ( 10 > now.getMinutes() ) ? '0' + now.getMinutes() : now.getMinutes(); let _second = ( 10 > now.getSeconds() ) ? '0' + now.getSeconds() : now.getSeconds(); return now.getFullYear() + '-' + _month + '-' + _day + ' ' + _hour + ':' + _minute + ':' + _second;}

用法:

let time = nowTime();//2019-12-12 12:12:12

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。