简体   繁体   中英

Get next/previous ISO week and year in PHP

我需要一个以ISO周和ISO年为参数并返回下一个ISO周和年的函数(以及返回前一个ISO周/年的函数)。

So answer for 4 day so i give it a shot:

<?php

// Start with Timstamp 0, else the seconds might be off
$x = new DateTime("1970-01-01 00:00:00");
$x->setISODate(2010, 2);
echo $x->format("Y-m-d H:i:s"); // 2010-01-11 00:00:00

$x->modify("+1 week");

echo $x->format("Y-m-d H:i:s"); // 2010-01-18 00:00:00

// Now for the next ISO Week
echo $x->format("Y W"); // 2010 03

Hope that helps, else let me know :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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