Get friday from week number and year in javascript

后端 未结 4 1992
执笔经年
执笔经年 2020-12-11 19:22

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;         


        
4条回答
  •  抹茶落季
    2020-12-11 20:08

    i think if i should not use any date library i would:

    assuming u use a christian week, where sunday is the frist day of the week. this is neccessary to find out if the first days in a year belong to the first week of the year or not.

    create an array. months = new Array(31,28,31, ... ) if(year % 4 == 0) then february has 29 days.

    days = num_week * 7;

    then iterate over the month and decrease days by month[current]. if days gets negative increase days with the current month days again.

    result: year-(current+1)-days

    i hope this helps you. what u have to add on your own is the handling for january and the first days.

提交回复
热议问题