没有这个api。只能自己写:
获取该年份,判断闰年平年
判定该年1月1日是周几,并记录
按照月份以及日期进行日期的排列
创建二维数组,第一层存储周数,第二层存储具体日期
for循环,对数组写入数据
完成
这样就可以完成一个简单的周数存储。当然也可以用对象的形式,创建更多的对象检索属性,优化周数检索速度
<%@ page language="java" import="javautil" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 401 Transitional//EN"
" >
<script>
function getInfo(year, month) {
var d = new Date();
// what day is first day
dsetFullYear(year, month-1, 1);
var w1 = dgetDay();
if (w1 == 0) w1 = 7;
// total day of month
dsetFullYear(year, month, 0);
var dd = dgetDate();
// first Monday
if (w1 != 1) d1 = 7 - w1 + 2;
else d1 = 1;
week_count = Mathceil((dd-d1+1)/7);
documentwrite(year + "年" + month + "月有" + week_count +"周<br/>");
for (var i = 0; i < week_count; i++) {
var monday = d1+i7;
var sunday = monday + 6;
var from = year+"/"+month+"/"+monday;
var to;
if (sunday <= dd) {
to = year+"/"+month+"/"+sunday;
} else {
dsetFullYear(year, month-1, sunday);
to = dgetFullYear()+"/"+(dgetMonth()+1)+"/"+dgetDate();
}
documentwrite("第"+(i+1)+"周 从" + from + " 到 " + to + "<br/>");
}
}
getInfo(2013,12);
</script>
function dayList(len){
var d = '日一二三四五六';
var sDay = new Date()getDay();
var result = [];
var i = 0;
while(i<len){
var tmp = sDay+i ;
if(!((sDay+i) <7)){
tmp = (sDay+i)%7
}
resultpush('周'+dcharAt(tmp));
i++;
}
return result;
}
consolelog(dayList(17));
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
td{
border:1px solid;
}
button{
margin: 5px;
}
</style>
<script>
windowonload = function(){
var cells = documentgetElementById('monitor')getElementsByTagName('td');
var clen = cellslength;
var currentFirstDate;
var formatDate = function(date){
var year = dategetFullYear()+'年';
var month = (dategetMonth()+1)+'月';
var day = dategetDate()+'日';
var week = '('+['星期天','星期一','星期二','星期三','星期四','星期五','星期六'][dategetDay()]+')';
return year+month+day+' '+week;
};
var addDate= function(date,n){
datesetDate(dategetDate()+n);
return date;
};
var setDate = function(date){
var week = dategetDay()-1;
date = addDate(date,week-1);
currentFirstDate = new Date(date);
for(var i = 0;i<clen;i++){
cells[i]innerHTML = formatDate(i==0 date : addDate(date,1));
}
};
documentgetElementById('last-week')onclick = function(){
setDate(addDate(currentFirstDate,-7));
};
documentgetElementById('next-week')onclick = function(){
setDate(addDate(currentFirstDate,7));
};
setDate(new Date());
}
</script>
</head>
<body>
<button id="last-week">上一周</button><button id="next-week">下一周</button>
<table id="monitor">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
var d = new Date(),
dd = dgetDay(),
friday = new Date((5 - dd)(3600241000)+dgetTime())getDate();
alert(friday);
以上就是关于js怎么获取每月的各周是本年的各第几周全部的内容,包括:js怎么获取每月的各周是本年的各第几周、js 怎么计算上一周下一周、js 获取某年某月有几周,以及每周的周一和周末是几号到几号等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)