[英]How to get previous year's date relative to week of year
How can I get the same day of the same ISO-8601 week number but in the previous year using php? 我怎样才能获得相同ISO-8601周数的同一天但是在前一年使用php?
I am familiar with extracting this soft of information from a time stamp. 我熟悉从时间戳中提取这些信息。 Is there a built-in way for me to go from day of week, week of year and year to time stamp? 从一周的一周,一年中的一周和一年到一年的时间戳,我都有内置的方式吗?
You can use the combination of both date
and strtotime
like so: 您可以使用date
和strtotime
的组合,如下所示:
// get the timestamp
$ts = strtotime('today');
// get year, week number and day of week
list($year, $week, $dow) = explode('-', date('Y-W-N', $ts));
// use the "YYYY-WXX-ZZ" format
$format = ($year - 1) . "-W$week-$dow";
echo date('Y-m-d', strtotime($format)), PHP_EOL;
I think you are looking for mktime. 我想你正在寻找mktime。 have a look here http://php.net/manual/en/function.mktime.php 看看http://php.net/manual/en/function.mktime.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.