0

I'm trying to use CakePHP's TimeHelper.

Let's say I have this date: Tue, 07 Jun 2011 10:53:31 GMT

Its' epoch time is: 1307444011

I need to get difference output with now, like this: 2 years, 24 days, 15 hours, 27 minutes and 43 seconds

I tried this:

$userCreatedTimeStr = $this->Time->timeAgoInWords(
       1307444011, array(
        'end' => '+10 year',
        'accuracy' => array('second' => 'second')
    )
);

But this code gives 2 years ago.

How can I fix this?

Edit: some test code is like this: http://apigen.juzna.cz/doc/cakephp/cakephp/source-class-CakeTimeTest.html#189-229

It seems like using core PHP functions is mandatory, rather than TimeHelper.

How to calculate the difference between two dates using PHP?

How to get time difference in minutes in PHP

4

1 回答 1

3

尝试将“格式”选项放入选项数组?

例如:

$userCreatedTimeStr = $this->Time->timeAgoInWords(
       1307444011, array(
        'end' => '+10 year',
        'format' => 'F jS, Y',
        'accuracy' => array('second' => 'second')
    )
);

编辑: CakePHP 像这样限制 timeAgoInWords 方法:

如果差值是一周或更长时间,则最低准确度级别是天

来源:http ://api.cakephp.org/2.3/class-CakeTime.html#_timeAgoInWords

我猜你试图做的事情根本不可能使用这种方法,至少在 2.3 版中是这样。

于 2013-07-01T11:08:00.210 回答