Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 一周的第一天_Php - Fatal编程技术网

Php 一周的第一天

Php 一周的第一天,php,Php,我想要一周的第一天,比如说我有第45周。现在我想知道本周第一个星期天的日期。 有人能建议我怎么做吗 谢谢你你应该 一些类似的代码 $next_sunday = strtotime('next sunday'); $next_week = strtotime('+1 week'); $next_sunday_of_next_week = strtotime('next sunday', $next_week); 如果您有月份、日期和年份,希望这对您有所帮助: $timestamp = mktim

我想要一周的第一天,比如说我有第45周。现在我想知道本周第一个星期天的日期。 有人能建议我怎么做吗

谢谢你

你应该

一些类似的代码

$next_sunday = strtotime('next sunday');
$next_week = strtotime('+1 week');
$next_sunday_of_next_week = strtotime('next sunday', $next_week);

如果您有月份、日期和年份,希望这对您有所帮助:

$timestamp = mktime(0, 0, 0, $month, $day, $year);
 echo date('c', $timestamp) = mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year);
如果您有时间戳,也可以这样做:

echo $date('c', mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year));
起始日期:

日期($str_格式,strtime($year.”W.$week..1”)


其中,
$str_format
是根据PHP
date()
的输出格式。。我使用
'mdy'

四处搜索,建议最多的是:

$year = "2009"; // date("Y");
$week = "45"; // date("W");

$firstDayOfWeek = strtotime($year."W".str_pad($week,2,"0",STR_PAD_LEFT));

print("The first day of week ".$week." of ".$year." is ".date("D, d-m-Y",$firstDayOfWeek));
基本上,这可以归结为让strotime为您完成工作。您填写“2009W45”,它将为您检索日期。 这里的陷阱是一周需要采用2位数的格式。因此,第1周需要为01,因此str_pad为零填充它