| 项目搜索 |
| |
|
代码片段库:
查看代码片段
浏览
| 提交新的代码片段
| 创建代码包
测算年度星期数
|
类型:
Full Script |
类别:
HTML Manipulation
|
许可证:
GNU General Public License |
语言:
JavaScript
|
描述:
自动计算出当前日期在年度中属于第几个星期
|
该代码片段的版本系列:
片段ID |
下载版本 |
提交时间 |
提交人 |
删除 |
4668 | 1.0 | 2003-10-13 23:11 | cbd001 | |
点击"下载版本"来下载该代码片段.
最新版本的代码片段: 1.0
脚本说明:
把如下代码加入<body>区域中:
<SCRIPT Language="JavaScript">
<!--
function weekNo() {
var totalDays = 0;
now = new Date();
years=now.getYear()
if (years < 1000)
years+=1900
var days = new Array(12); // Array to hold the total days in a month
days[0] = 31;
days[2] = 31;
days[3] = 30;
days[4] = 31;
days[5] = 30;
days[6] = 31;
days[7] = 31;
days[8] = 30;
days[9] = 31;
days[10] = 30;
days[11] = 31;
// Check to see if this is a leap year
if (Math.round(now.getYear()/4) == now.getYear()/4) {
days[1] = 29
}else{
days[1] = 28
}
// If this is January no need for any fancy calculation otherwise figure out the
// total number of days to date and then determine what week
if (now.getMonth() == 0) {
totalDays = totalDays + now.getDate();
}else{
var curMonth = now.getMonth();
for (var count = 1; count <= curMonth; count++) {
totalDays = totalDays + days[count - 1];
}
totalDays = totalDays + now.getDate();
}
var week = Math.round(totalDays/7);
return week;
}
document.write("现在是第 <b>"+weekNo()+"</b> 个星期("+years+"中的)")
// -->
</SCRIPT>
如果您修改了一个代码片段并且觉得很应该让别人共享,您可以把这作为这个代码片段的最新版本提交上来. |
|