5

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?

2 Answers 2

3

I think this would work...

$tDiff = 1303725600 - time();

$days = floor($tDiff / 86400);
$hours = ($tDiff / 3600) % 24;
$mins = ($tDiff / 60) % 60;
$secs = ($tDiff) % 60;
Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.