//时间戳转换为年月日时分秒时间格式。
function dateFormat(date) {
var date = new Date(date);
Y = date.getFullYear() + '-';
M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
return(Y + M + D + h + m + s );
}
alert(dateFormat(new Date());
//时间戳转换为年月日时间格式。
function dateFormatShort(date) {
var date = new Date(date);
Y = date.getFullYear() + '-';
M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
return(Y + M + D);
}
alert(dateFormatShort(new Date());
//时间戳转换为年月时间格式。
function dateFormatShort(date) {
var date = new Date(date);
Y = date.getFullYear() + '-';
M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
return(Y + M);
}
alert(dateFormatShort(new Date());
//年月日转时间戳
function dateFormattotime(date){
var str = date;
str = str.replace(/-/g,'/');
var date = new Date(str);
return date.getTime();
}
alert(dateFormattotime("2019-02-18")); //1550419200000