AndrewFerrara
AndrewFerrara

Reputation: 2403

Creating a unix timestamp countdown

I want to have a countdown to a unix timestamp: Where it counts down in seconds

Like this:

Expires in: 1d 10h 52m 25s

Heres an example timestamp: 1303725600

How could I do that?

Upvotes: 5

Views: 4014

Answers (2)

James C
James C

Reputation: 14159

I think this would work...

$tDiff = 1303725600 - time();

$days = floor($tDiff / 86400);
$hours = ($tDiff / 3600) % 24;
$mins = ($tDiff / 60) % 60;
$secs = ($tDiff) % 60;

Upvotes: 3

Chris Cherry
Chris Cherry

Reputation: 28574

I just made one of those. http://chrischerry.name/coachella

Check out the source for some ideas on how to do it. The "destination" date however isn't specified by a unix time stamp but that's easy enough to do.

var date = new Date(unix_timestamp*1000);

Its multiplied by 1000 because the javascript Date() wants the time in milliseconds, and unixtimestamps are in seconds.

Upvotes: 2

Related Questions