How to calculate time passed with PHP or Zend_Date?

老子叫甜甜 提交于 2019-12-04 20:40:26

Since you're already using the Zend Framework, there's a TimeSince view helper in the Zym Framework, which is a library of additional ZF extensions and helpers.

The TimeSince helper does basically exactly what you're trying to do:

Last updated <?= $this->timeSince($timestamp); ?> ago

Will output something like:

Last updated 8 hours ago

$time = sprintf("%d hours, %d minutes and %d seconds\n", $s / (1000 * 60 * 60), $s / (1000 * 60), $s);

Where $s is seconds

assuming your $datetime is the unix timestamp you can get $ms from (time() - $timestamp)

if you want a full on fuzzy timestamp creator see: http://plugins.trac.wordpress.org/browser/splees-fuzzy-datetime/trunk/splees_fuzzy_datetime.php

I have found Zend_Date alot easier to use with timestamp. Then format the output if you want (maybe use a view help to do that).

(this would have been a comment if I could)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!