可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm Trying to get the current date plus 7 days to display.
Example: Today is August 16, 2012, so this php snippet would output August 23, 2012.
$date = strtotime($date); $date = strtotime("+7 day", $date); echo date('M d, Y', $date);
Right now, I'm getting: Jan 08, 1970. What am I missing?
回答1:
strtotime
will automatically use the current unix timestamp to base your string annotation off of.
Just do:
$date = strtotime("+7 day"); echo date('M d, Y', $date);
Added Info For Future Visitors: If you need to pass a timestamp to the function, the below will work.
This will calculate 7 days
from yesterday:
$timestamp = time()-86400; $date = strtotime("+7 day", $timestamp); echo date('M d, Y', $date);
回答2:
$date = new DateTime(date("Y-m-d")); $date->modify('+7 day'); $tomorrowDATE = $date->format('Y-m-d');
回答3:
If it's 7 days from now that you're looking for, just put:
$date = strtotime("+7 day", time()); echo date('M d, Y', $date);
回答4:
<?php print date('M d, Y', strtotime('+7 days') );
回答5:
you didn't use time() function that returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). use like this:
$date = strtotime(time()); $date = strtotime("+7 day", $date); echo date('M d, Y', $date);
回答6:
$now = date('Y-m-d'); $start_date = strtotime($now); $end_date = strtotime("+7 day", $start_date); echo date('Y-m-d', $start_date) . ' + 7 days = ' . date('Y-m-d', $end_date);
回答7:
This code works for me:
<?php $date = "21.12.2015"; $newDate = date("d.m.Y",strtotime($date."+2 day")); echo $newDate; // print 23.12.2015 ?>