//时间戳转换为年月日时分秒时间格式。
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
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态