简体   繁体   English

Laravel或PHP,我有一个月和一天的星期数,我怎么能得到这些日期..?

[英]Laravel or php I have a week number of a month and a day, how can i get the date of these..?

i am used 我很习惯

date()    strtotime()

and so on... I need the date for a given week number of the month and day of the month.. Example., "3rd Week of the every month and Monday in every month for a year(Any one)" I need these to conditions meet dates for a whole year.. 依此类推...我需要给定日期的月份和月份中的某几天的日期。例如,“一年中每月的第三个星期和每月的每个星期一(任意一年)”这些要符合条件的日期才能整整一年。

Can you help me..? 你能帮助我吗..?

for all mondays of a year: 一年中的所有星期一:

$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/>"; 
}

suppose you save month number in variable $month: 假设您将月份号保存在变量$ month中:

$firstDayOfmonth = mktime (0, 0, 0, $month, 1, date("Y"));
$threeweeksLater = strtotime(date("Y-m-d", strtotime($firstDayOfmonth)) . " +3 week");

now suppose you have year number in variable $year and week number in $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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM