前面一周的时间段

前言:获取今天至前面一周的时间

<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8" />
	</head>
	<body>
		<script src="jquery.js"></script>
		<script>
			var GAME = {};
			GAME.monthstart = ''; //当前月的,第一天
			GAME.monthend = ''; //当前月的,今天
			
			formatDate();
			function formatDate() {
				now = new Date();
				now2 = new Date();
				var year = now.getFullYear(),
					month = now.getMonth() + 1,
					date = 1,
					date2 = now.getDate(),
					hour = now.getHours(),
					minute = now.getMinutes(),
					second = now.getSeconds();
				minute = checkTime(minute);
				month = checkTime(month);
				date = checkTime(date);
				date2 = checkTime(date2);
				hour = checkTime(hour);
				second = checkTime(second);

				var nowdate = new Date();
				var oneweekdate = new Date(nowdate - 7 * 24 * 3600 * 1000);
				var m = oneweekdate.getMonth() + 1;
				var d = oneweekdate.getDate();
				var month0 = checkTime(m);
				var d0 = checkTime(d);

				GAME.monthstart = year + "-" + month0 + "-" + d0
				GAME.monthend = year + "-" + month + "-" + date2
			}

			function checkTime(i) {
				if(i < 10) {
					i = "0" + i
				}
				return i
			}
			console.log(GAME.monthstart);
			console.log(GAME.monthend);
		</script>
	</body>

</html>

猜你喜欢

转载自blog.csdn.net/dongsdh/article/details/82854296