简体   繁体   English

如何从天数,星期数和年份中获取特定日期

[英]How to get specific date from days, number of week and year

I want get specific date based on days, number of week and years, 我想根据天数,星期数和年数来确定具体日期,

$days = "Monday";
$number_of_week = date('W'); // 1 to 42 total number of weeks in years
$year = date('Y'); // 2017

getSpecificDate($days, $number_of_week, $year);

it will return 它将返回

2017-02-20 2017年2月20日

How to get that? 如何获得?

The function like this: 像这样的功能:

$year : year $ year:年

$week : if 1~9, should prepended 0, like 01~09 $ week:如果1〜9,则应加0,例如01〜09

$days : 1~7 $ days:1〜7

getSpecificDate($days, $week, $year) {

    return date("Y-m-d", strtotime($year . "W" . sprintf("%02u", $week) . $days)); 

}

Try this: 尝试这个:

$days = "Tuesday";
$number_of_week = date('W'); // 1 to 42 total number of weeks in years
$year = date('Y'); // 2017

function getSpecificDate($days, $number_of_week, $year){
   $week_day = date( "Y-m-d", strtotime($year."W".$number_of_week) );

   $date_time = strtotime($week_day.' next '.$days);

   return date('Y-m-d', $date_time);
}

echo getSpecificDate($days, $number_of_week, $year);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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