本文介绍了从星期数和年份在javascript中获取星期五的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有周数和年份,需要在该周和年份中找出日期(星期五)。

I have week number and year, need to find out date (friday) in that week and year.

function getFriday(week_num, year)
{
    ?

    return friday_date_object;
}

我该怎么做?

推荐答案

第1周是第一个星期四的星期。

The week #1 is the week with the first Thursday.

这是一个函数来获取任何一天:

Here is a function to get any day:

var w2date = function(year, wn, dayNb){
    var j10 = new Date( year,0,10,12,0,0),
        j4 = new Date( year,0,4,12,0,0),
        mon1 = j4.getTime() - j10.getDay() * 86400000;
    return new Date(mon1 + ((wn - 1)  * 7  + dayNb) * 86400000);
};
console.log(w2date(2010, 1, 4));

周数从1开始,直到52或53,这取决于年份。

对于日数,0是星期一,1是星期二,...和4是星期五

week numbers start at 1 until 52 or 53 it depends the year.
For the day numbers, 0 is Monday, 1 is Tuesday, ... and 4 is Friday

这篇关于从星期数和年份在javascript中获取星期五的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 01:11