JS Date日期时间对象格式化

JS Date日期时间对象格式化


function dateToStr( datetime ) {
	var year = datetime.getFullYear(),
	month = datetime.getMonth()+1,
	date = datetime.getDate(),
	hour = datetime.getHours(),
	minutes = datetime.getMinutes(),
	second = datetime.getSeconds();
	if ( month < 10 ) {
		month = "0" + month;
	}
	if ( date < 10 ) {
		date = "0" + date;
	}
        if ( hour < 10 ) {
		hour = "0" + hour;
	}
	if ( minutes < 10 ) {
		minutes = "0" + minutes;
	}
	if ( second < 10 ) {
		second = "0" + second;
	}
	return (year+"-"+month+"-"+date+" "+hour+":"+minutes+":"+second);
}


你可能感兴趣的:(javascript,格式化,javaScript)