时间戳转换为年月日时分秒时间格式

版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/csdnluolei/article/details/86300617

//时间戳转换为年月日时分秒时间格式。
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 );
}
//时间戳转换为年月日时间格式。
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);
}
//年月日转时间戳
function dateFormattotime(date){
	var str = date;
	str = str.replace(/-/g,'/');
	var date = new Date(str);
	return date.getTime();
}

猜你喜欢

转载自blog.csdn.net/csdnluolei/article/details/86300617
今日推荐