[英]I have the week number of a month, and want to get the first date within that week in PHP
[英]Laravel or php I have a week number of a month and a day, how can i get the date of these..?
我很習慣
date() strtotime()
依此類推...我需要給定日期的月份和月份中的某幾天的日期。例如,“一年中每月的第三個星期和每月的每個星期一(任意一年)”這些要符合條件的日期才能整整一年。
你能幫助我嗎..?
一年中的所有星期一:
$date = '2016-01-01';
$y = date('Y', strtotime("$date"));
$x = $y;
while(1){
$date = date('Y-m-d', strtotime("next Monday $date"));
$y = date('Y', strtotime("$date"));
if($x != $y) break;
echo $date."<br/>";
}
假設您將月份號保存在變量$ month中:
$firstDayOfmonth = mktime (0, 0, 0, $month, 1, date("Y"));
$threeweeksLater = strtotime(date("Y-m-d", strtotime($firstDayOfmonth)) . " +3 week");
現在假設您在變量$ year中有年號,在$ week中有周號:
$firstDayOfEveryWeek = mktime (0, 0, 0, $month, ($week-1)*7, $year);
$threeweeksLater = strtotime(date("Y-m-d", strtotime($firstDayOfEveryWeek)) . " +3 days");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.