Get next/previous ISO week and year in PHP

前端 未结 1 1295
执念已碎
执念已碎 2020-12-21 15:35

I need a function that takes an ISO week and an ISO year as parameter and returns the next ISO week and year (and a function that returns the previous ISO week/year).

相关标签:
1条回答
  • 2020-12-21 16:08

    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 :)

    0 讨论(0)
提交回复
热议问题