我想要这样的strtotime日期格式- Fri Jun 15 05:38:11 +1000 2012我该怎么做呢?基本上我需要对它进行strtotime,然后执行以下操作- $ago = time()-strtotime(Fri Jun 15 05:38:11 +1000 2012);,然后执行以下操作-
$ago = $ago / (60*60*24);
echo $ago.' days ago';所以我需要一件事- strtotime(Fri Jun 15 05:38:11 +1000 2012),它会像它需要的那样工作。
如果这种类型的日期不能是strtotime,那么我如何编辑它,使它可以是strtotime?
发布于 2012-06-20 03:24:00
比较不同之处,用floor/ceil来表示圆形。
$now = time();
$then = strtotime($var);
echo floor(($now - $then) / 86400) . " days ago";发布于 2012-06-20 03:27:48
试试这个(OOP风格,有一个过程上的等价物):
<?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");
?>发布于 2012-06-20 03:22:47
DateTime::createFromFormat()方法允许您定义要解析的日期字符串的格式。
https://stackoverflow.com/questions/11107801
复制相似问题