2011-04-13 35 views
2

我需要包括一些东西在PHP 5中使用time_since()函数或是它被取代?time_since()PHP函数

+0

看看http://stackoverflow.com/questions/2952361/date-time-convert-to-time-since-php – bensiu 2011-04-13 01:17:53

回答

0

It doesn't look like that function ever existed in PHP。你的意思是time()

但是,你可以得到的时间,因为像这样的事件......

$timeSince = time() - strtodate('last Saturday'); 

您也可以使用对象DateTime

$now = new DateTime(); 

$timeSince = $now->diff(new DateTime('last Saturday'), TRUE); 

请注意,diff()方法直到PHP 5.3才被引入。

+0

如果我使用的unix时间戳可以放在这个地方,如果上周六在以上?我正在寻找3天的输出2小时15分钟前 – 2011-04-13 01:22:57

+0

没关系,这是我写的一个函数,它隐藏在我的包含文件thx中,试图帮助! – 2011-04-13 01:29:21

0

PHP working out time since the post

如果你使用PHP 5.3或更新版本,您可以加入到PHP新的日期和时间类的优势。

具体而言,DateTime具有返回DateInterval类的diff方法,然后可以对其进行格式化。