How to convert week number and year into unix timestamp?

后端 未结 3 812
自闭症患者
自闭症患者 2020-12-03 21:00

I\'m trying to group together dates into a week number and year, and then I want to convert that week number back into a unix timestamp. How can I go about doing this?

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 21:11

    strtotime('1/1/2011 + 4 weeks') (1/1 ist always in week number one; this would bring me to week number five). if you want any timestamp in the week then that's all you need, else you would have to go to the monday in this week:

    $t = strtotime('1/1/2011 + 4 weeks');
    $t -=  24 * 60 * 60 * date('w', $t);
    

    Update: Instead of 1/1/2011 use the first monday in 2011. The 2nd calculation is not needed anymore.

提交回复
热议问题