Week number and Week day

折月煮酒 提交于 2020-01-11 10:52:27

问题


I have week number of current year and week day generated by date() like this.

$week_number = date('W');
$week_day = date('w');

I need to format this. How can I get starting date of this week? Or day of month with $week_number and $week_day?


回答1:


Update:

Maybe this article helps you. It describes how to get the start and end date of a given week.

<?php
// Monday
echo date(
    datetime::ISO8601,
    strtotime("2006W37"));

// Sunday
echo date(
    datetime::ISO8601,
    strtotime("2006W377"));
?>

Where the format is <year>W<week-number><daynumber> and Monday is 1.

Update 2:

Maybe another possibility is to use strtotime() this way:

echo strtotime("last Monday");
echo strtotime("next Sunday");

You can combine this with date() to get the date in the desired format.


You can get the day of the month with date('d') directly.

date() documentation.



来源:https://stackoverflow.com/questions/2372331/week-number-and-week-day

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!