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;
}

猜你喜欢

转载自blog.csdn.net/qq_42037231/article/details/84752763