开发者

Get future timestamps

Would it be possible to get the unix timestamp 7 days from now?

开发者_StackOverflow

Would be awesome!


Yes, get the unix timestamp and add 25200 to it. If you want to format that timestamp you can use date().

$future = time() + (60 * 60 * 24 * 7);
date("o", future);

And from the PHP docs for time()

date('Y-m-d', strtotime('+1 week'))


Sure.

Get the current timestamp. Add 7 days worth of seconds.

Note: The timestamp "7 days ahead" (in terms of 7 * 86400 seconds) of the current timestamp may not represent the same day-of-week or the same hour in the day (yay daylight savings!) or even the same second (rare, yay leap-seconds!).


time() + (60 * 60 * 24 * 7);  // "good enough"
strtotime('+7 days');         // daylight savings save


Just add seven days?

$future = time() + 60*60*24*7;
//      seconds  ---^  ^ ^  ^ 
//        minutes   ---^ ^  ^
//          hours     ---^  ^      
//            days       ---^

See time().... oh, the example given there does exactly what you want... I guess you have not read the manual before.


The proper way of doing this on a recent version of PHP is using the DateTime object (in my opinion).

$date = new DateTime('now'); // can be anyting else too
$date->modify('+1 week');

// PHP 5.3
$future = $date->getTimeStamp(); 

// PHP 5.2
$future = $date->format('U');


$now = time() + (7 * 24 * 60 * 60);

Get the current unix timestamp using time() and then multiply 60 seconds, 60 minutes, 24 hours, and 7 days.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜