本站即日起正式部署SSL证书启用https安全连接, 联系站长:416326801#qq.com(#改成@)

js时间戳转换

85 Views 标签: JavaScript

//时间戳转换
function timestampToSecond(timestamp) {
	var date = new Date(timestamp);
	h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + '小时';
	m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()+"分";
	s = date.getSeconds();

	return h + m;
}
function timestampToTime(timestamp) {
	var date = new Date(timestamp);
	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();

	return Y + M + D + h + m;
}
function timestampToTimeToMonth(timestamp) {
	var date = new Date(timestamp);
	Y = date.getFullYear() + '-';
	M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);

	return Y + M;
}

function timestampToTimeToDay(timestamp) {
	var date = new Date(timestamp);
	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;
}

您可能感兴趣: