function formatDate(date, format) { |
if (!date) return '' ; |
format = format || 'yyyy-MM-dd' ; |
if ( typeof date === 'string' ) { |
date = new Date(date.replace(/-/g, '/' )); |
} |
var dict = { |
'yyyy' : date.getFullYear(), |
'MM' : ( '0' + (date.getMonth() + 1)).slice(-2), |
'dd' : ( '0' + date.getDate()).slice(-2), |
'HH' : ( '0' + date.getHours()).slice(-2), |
'mm' : ( '0' + date.getMinutes()).slice(-2), |
'ss' : ( '0' + date.getSeconds()).slice(-2), |
}; |
return format.replace(/(yyyy|MM|dd|HH|mm|ss)/g, function () { |
return dict[arguments[0]]; |
}); |
} |
//日期-转/ |
formatDate( '2023-03-04' , 'yyyy/MM/dd' ) |