| 项目搜索 |
| |
|
代码片段库:
查看代码片段
浏览
| 提交新的代码片段
| 创建代码包
最近的星期天
|
类型:
Full Script |
类别:
HTML Manipulation
|
许可证:
GNU General Public License |
语言:
JavaScript
|
描述:
自动检测最近的两个星期天是几月几号,有时会有用的
|
该代码片段的版本系列:
片段ID |
下载版本 |
提交时间 |
提交人 |
删除 |
4724 | 1.0 | 2003-10-14 16:44 | cbd001 | |
点击"下载版本"来下载该代码片段.
最新版本的代码片段: 1.0
脚本说明:
把如下代码加入<body>区域中:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function isLeapYear () {
year = new Date().getYear();
year += (year < 2000 ? 1900 : 0);
return (year % 4==0 && year % 100!=0 || year % 400==0);
}
function formatDate(date) {
mymonth = date.getMonth()+1;
myweekday = date.getDate();
return (mymonth + "/" + myweekday);
}
function printWeek() {
beginday = 0; // first day of each week
// 0 = sunday, 1= monday .... 6 = saturday
var dayarray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
dayarray[1] = (isLeapYear()) ? 29 : 28;
dayfactor = 86400000; // one day equals 86400000 milliseconds
weekstart = new Date();
weekend = new Date();
while (weekstart.getDay() != beginday) {
weekstart.setTime(weekstart.getTime() - dayfactor);
}
weekend.setTime(weekend.getTime() + 6*dayfactor);
document.write("最近两个星期天为: " + formatDate(weekstart) + " - " + formatDate(weekend));
}
// End -->
</script>
<script>
printWeek();
</script>
如果您修改了一个代码片段并且觉得很应该让别人共享,您可以把这作为这个代码片段的最新版本提交上来. |
|