note 57583 modified in function.time by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 17:04:30 +0000 |
| Subject: | note 57583 modified in function.time by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153342@lists.php.net to get a copy of this message | ||
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
--was--
* A simple function for calculating the number of seconds, minutes, etc in a timestamp is here:
http://aidanlister.com/repos/v/Duration.php
Example:
<?php
$time = 60*60*2 + 20*60 + 5;
// Gives 2 hours, 20 minutes, 5 seconds
echo Duration::toString($time);
?>
* 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
http://php.net/manual/en/function.time.php