Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a Zend Framework ViewHelper I wrote to do this, you could easily modify this to not use the ZF specific code:</p> <pre><code>/** * @category View_Helper * @package Custom_View_Helper * @author Chris Jones &lt;leeked@gmail.com&gt; * @license New BSD License */ class Custom_View_Helper_HumaneDate extends Zend_View_Helper_Abstract { /** * Various time formats */ private static $_time_formats = array( array(60, 'just now'), array(90, '1 minute'), // 60*1.5 array(3600, 'minutes', 60), // 60*60, 60 array(5400, '1 hour'), // 60*60*1.5 array(86400, 'hours', 3600), // 60*60*24, 60*60 array(129600, '1 day'), // 60*60*24*1.5 array(604800, 'days', 86400), // 60*60*24*7, 60*60*24 array(907200, '1 week'), // 60*60*24*7*1.5 array(2628000, 'weeks', 604800), // 60*60*24*(365/12), 60*60*24*7 array(3942000, '1 month'), // 60*60*24*(365/12)*1.5 array(31536000, 'months', 2628000), // 60*60*24*365, 60*60*24*(365/12) array(47304000, '1 year'), // 60*60*24*365*1.5 array(3153600000, 'years', 31536000), // 60*60*24*365*100, 60*60*24*365 ); /** * Convert date into a pretty 'human' form * Now with microformats! * * @param string|Zend_Date $date_from Date to convert * @return string */ public function humaneDate($date_from) { $date_to = new Zend_Date(null, Zend_Date::ISO_8601); if (!($date_from instanceof Zend_Date)) { $date_from = new Zend_Date($date_from, Zend_Date::ISO_8601); } $dateTo = $date_to-&gt;getTimestamp(); // UnixTimestamp $dateFrom = $date_from-&gt;getTimestamp(); // UnixTimestamp $difference = $dateTo - $dateFrom; $message = ''; if ($dateFrom &lt;= 0) { $message = 'a long time ago'; } else { foreach (self::$_time_formats as $format) { if ($difference &lt; $format[0]) { if (count($format) == 2) { $message = $format[1] . ($format[0] === 60 ? '' : ' ago'); break; } else { $message = ceil($difference / $format[2]) . ' ' . $format[1] . ' ago'; break; } } } } return sprintf('&lt;abbr title="%sZ"&gt;%s&lt;/abbr&gt;', $date_from-&gt;get('YYYY-MM-ddTHH:mm:ss'), $message ); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload