1.查询某个日期是今年第几周:
1 var weekofyear = (new Date(2017,3,13)-new Date("2017-01-01"))/(24*60*60*7*1000)|0+1; 2 3 console.log(‘第‘+weekofyear+‘周‘ );
输出:第15周
2.周转具体日期:
var tDate = new Date(); var day = (function(){ var tYear = 2017 var tWeek = 15; //2017年第15周 tDate = new Date(((tWeek+1)*7+(tYear-1970)*365)*24*60*60*1000); var day = tDate.getDay(); return (day==0)?7:day; })(); var monday =new Date(tDate.getTime() - (day)*24*60*60*1000); console.log(monday.getFullYear()+‘-‘+(monday.getMonth()+1)+‘-‘+(monday.getDate()+1));
输出:2017-4-10
时间: 2024-11-07 04:53:19