I would like to strtotime dateformat like this - Fri Jun 15 05:38:11 +1000 2012 How could I do that? Basically I need to strtotime it, then do the following - $ago = time()-strtotime(Fri Jun 15 05:38:11 +1000 2012);
and then do this -
$ago = $ago / (60*60*24);
echo $ago.' days ago';
So I need one thing - strtotime(Fri Jun 15 05:38:11 +1000 2012) which will work as it need to work.
If this type of date cannot be strtotime, then how can I edit it, so it could be strtotime?
Try this (OOP style, there's a procedural equivalent):
<?php
$str = "Fri Jun 15 05:38:11 +1000 2012";
// From here: http://is2.php.net/manual/en/datetime.createfromformat.php
$datetime = DateTime::createFromFormat('D M d H:i:s T Y', $str);
$now = new DateTime();
// From here: http://is2.php.net/manual/en/datetime.diff.php
$interval = $now->diff($datetime);
echo $interval->format("%R%a days");
?>
DateTime::createFromFormat()
方法允许您定义要解析的日期字符串的格式。
Compare the difference and use floor/ceil to round.
$now = time();
$then = strtotime($var);
echo floor(($now - $then) / 86400) . " days ago";
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.