如何像这样排列时间日期格式


How to strtotime date format like this

>我想像这样设置时间日期格式 - 周五 6 月 15 日 05:38:11 +1000 2012 我该怎么做?基本上我需要对它进行计时,然后执行以下操作 - $ago = time()-strtotime(Fri Jun 15 05:38:11 +1000 2012);然后这样做 -

$ago = $ago / (60*60*24);
echo $ago.' days ago';

所以我需要一件事 - strtotime(周五 6 月 15 日 05:38:11 +1000 2012) 它将根据需要工作。

如果这种类型的日期不能是strtotime,那么我该如何编辑它,所以它可以是strtotime?

试试这个(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");
?>

比较差异并使用地板/ceil进行四舍五入。

$now = time();
$then = strtotime($var);
echo floor(($now - $then) / 86400) . " days ago";

DateTime::createFromFormat() 方法允许您定义要分析的日期字符串的格式。