Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
752 views
in Technique[技术] by (71.8m points)

date - Get next/previous ISO week and year in PHP

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...