1. 程式人生 > >js獲取當前時間 格式格式YYYY-MM-DD HH:MM

js獲取當前時間 格式格式YYYY-MM-DD HH:MM

//獲取當前時間,格式YYYY-MM-DD HH:MM
function getNowFormatDate() {
	var date = new Date();
	var seperator1 = "-";
	var seperator2 = " ";
	var seperator3 = ":";
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var hours = date.getHours();
	var minutes = date.getMinutes();
	var currentdate = year + seperator1 + month + seperator1 + strDate + seperator2 + hours + seperator3 + minutes;
     return currentdate;
}