Generate countdown in any format
Multi format countdown class can convert between different formats of time units. User can specify time left to count in any combinations of time units as seconds, minutes, hours, days, weeks, months and years and retrieve in any other combinations of time units
User might also provide timestamp to which time left was relatively calculated.
This class returns values in full time units, for example, if you provide 80 seconds, and request format in minutes, then only 1 minute will be returned and 20 seconds will be cut off.
Contents
Download
Example codes
<?php include("countdown.php"); //2 years 2 months 1 week 5 days 20 hours 30 minutes 40 seconds //from Sun, 10 Apr 2011 00:09:20 +0300 //provided value in seconds $cd = new countdown(array("s"=>69539440), 1302383360); echo "<pre>"; //get in years, months, weeks, days, hours, minutes and seconds print_r($cd->get()); echo "</pre>"; //114 weeks 6 days 1230 minutes 40 seconds //from now //provided value in weeks, days, minutes, seconds $cd = new countdown(array("w" => 114, "d" => 6, "i" => 1230, "s" => 40)); echo "<pre>"; //get in seconds print_r($cd->get(array("s"))); echo "</pre>"; //80 seconds //from now //provided value in seconds $cd = new countdown(array("s" => 80)); echo "<pre>"; //get in minutes (returns only full minutes) print_r($cd->get(array("i"))); echo "</pre>"; ?>
Examples in action
Example scripts provided with package in action:
Method list
Constructor
| Method name | new countdown($time, $rel = time()) |
| Description | Provide time left in any format and timestamp to which time left was calculated |
| Input parameters | array $time - time left provided in format using any combinations of seconds, minutes, hours, days, weeks, months and years. Keys for formats and meanings:
int $rel - timestamp to which provided time left is relative to (default value - current timestamp) |
| Example input |
//2 days and 3000 seconds
$cd = new countdown(array("d"=>2, "s"=>3000));
|
Get time left in any format
| Method name | get($time = array("y", "m", "w", "d", "h", "i", "s")) |
| Description | Get time left in any combinations of years, months, weeks, days, hours, minutes, seconds |
| Input parameters | array $time - array with format, in which units to return time, as values of array. Keys for formats and meanings:
|
| Example input |
//get years, days, hours, minutes and seconds
get(array('y','d','h','i','s'));
|
Latest changes
None for now
Rate us
Try it out and Rate on PHPclasses.org
Support
PHP classes support forum or comments below
You may also be interested in:
Powered by BlogAlike.com










