js获取当前时间并转化成年月日时分秒格式

var  date = new Date();//Thu Oct 28 2021 17:51:08 GMT+0800 (中国标准时间)

var timestamp=data.getTime(); //1635414668773
 
var Y = date.getFullYear(); //2021
 
var M = date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1; //10
 
var D = date.getDate(); //28
 
var h = date.getHours(); //17
 
var m = date.getMinutes(); //51
 
var s = date.getSeconds() < 10 ? '0'+ date.getSeconds() :  date.getSeconds(); //08
 
var yymmdd=Y + '-' + M + '-' + D; //2021-10-28

var yymmddhhmmss=Y + '-' + M + '-' + D + ' ' + H+ ':' + m + ':' + s; //2021-10-28 17:51:08

Guess you like

Origin blog.csdn.net/Lc_style/article/details/121019730