-
Notifications
You must be signed in to change notification settings - Fork 3
/
date.html
61 lines (45 loc) · 1.8 KB
/
date.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta charset="utf-8" />
</head>
<body>
<script>
var now = new Date();
var days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
var dates = [];
var date = ((now.getDate() < 10) ? '0' : '') + now.getDate();
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}
var today = days[now.getDay()] + ',' +
months[now.getMonth()] + ' ' +
date + ',' +
(fourdigits(now.getYear()));
document.write(today);
//Friday,October 21,2016
function getLastDay(year, month) {
var new_year = year; //取当前的年份
var new_month = month++;//取下一个月的第一天,方便计算(最后一天不固定)
if (month > 12) {
new_month -= 12; //月份减
new_year++; //年份增
}
var new_date = new Date(new_year, new_month, 1); //取当年当月中的第一天
return (new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate();//获取当月最后一天日期
}
//获取一个月的所有日期
function getAllDatesForAMonth(year, month) {
var lastDay = getLastDay(year, month);
var allDates = [];
for (var i = 0; i < lastDay; i++) {
allDates.push(i+1);
}
return allDates;
}
</script>
</body>
</html>