note 57583 deleted from function.time by sobak
| From: | sobak@php.net | Date: | Thu, 01 Dec 2016 05:59:00 +0000 |
| Subject: | note 57583 deleted from function.time by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207790@lists.php.net to get a copy of this message | ||
Note Submitter: aidan at php dot net
----
A simple function for calculating the number of seconds, minutes, etc in a timestamp is here:
http://aidanlister.com/2004/04/making-time-periods-readable/
Example:
<?php
echo time_duration(100000000);
// 3 years, 2 months, 19 hours, 22 minutes, 16 seconds
echo time_duration(100000000, null, true);
// 3 years, 2 months, 0 weeks, 0 days, 19 hours, 22 minutes, 16 seconds
echo time_duration(100000000, 'yMw');
// 3 years, 2 months
echo time_duration(100000000, 'd');
// 1157 days
?>
It is also worth noting:
* For manipulating arbitrary format, or length timestamps, see the PEAR::Date class.
http://pear.php.net/package/Date/
* PHP 6 will be shipping a new inbuilt date and timestamp manipulation API. It's available on
PECL here:
http://pecl.php.net/package/datetime