如何使用这样的strtotime日期格式

时间:2012-06-19 19:14:47

标签: php

我想像这样strtotime dateformat - 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?

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

比较差异并使用floor / ceil进行回合。

$now = time();
$then = strtotime($var);

echo floor(($now - $then) / 86400) . " days ago";
相关问题