记录:JS获取当前年、月、日、时、分、秒

function getCurrentDateTime(){
	let date = new Date();
	let year = date.getFullYear();
	let month = date.getMonth() + 1;
	let day = date.getDate();
	let hours = date.getHours();
	let minutes = date.getMinutes();
	let seconds = date.getSeconds();
	function fillZero(str) {
		let realNum;
		if (str < 10) {
			realNum = '0' + str;
		} else {
			realNum = str;
		}
		return realNum;
	};
	return {
		YYYY: year + '',
		YMD: year + "-" + fillZero(month) + "-" + fillZero(day),
		HMS: fillZero(hours) + ":" + fillZero(minutes) + ":" + fillZero(seconds),
		YMDHMS: year + "-" + fillZero(month) + "-" + fillZero(day) + " " + fillZero(hours) + ":" + fillZero(minutes) + ":" + fillZero(seconds)
	};
},

上一篇:计算对称日


下一篇:20211202