Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

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.

Note that user must set default time zone for countdown formats to be properly 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

Back to method list

Method namenew countdown($time, $rel = time())
DescriptionProvide 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:

  • s - seconds
  • i - minutes
  • h - hours
  • d - days
  • w - weeks
  • m - months
  • y - years

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

Back to method list

Method nameget($time = array("y", "m", "w", "d", "h", "i", "s"))
DescriptionGet 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:

  • s - seconds
  • i - minutes
  • h - hours
  • d - days
  • w - weeks
  • m - months
  • y - years

Example input
//get years, days, hours, minutes and seconds
get(array('y','d','h','i','s'));

Latest changes

None for now

Rate us

Like our script? Rate it at PHP > Hot Scripts

Scripts.com
RATE ME!

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

blog comments powered by Disqus