javascript[es6]获取时间格式yyyy-MM-dd HH:ss:mm

javascript[es6]获取时间格式yyyy-MM-dd HH:ss:mm

 function getDateYYYYMMddHHMMSS(){
    const date = new Date();
    const month = (date.getMonth() + 1).toString().padStart(2, '0');
    const strDate = date.getDate().toString().padStart(2, '0');
    const starHours = date.getHours().toString().padStart(2, '0');
    const starMinutes = date.getMinutes().toString().padStart(2, '0');
    const starSeconds = date.getSeconds().toString().padStart(2, '0');
    return `${date.getFullYear()}-${month}-${strDate} ${starHours}:${starMinutes}:${starSeconds}`;
} 

 

posted @ 2021-06-25 09:59  创客未来  阅读(960)  评论(0)    收藏  举报