1

I try to modify the keith-wood countdown timer to accept a future unix timestamp and hide the days.

To hide the days you use $('#noDays').countdown({until: liftoffTime, format: 'HMS'}); as the example at http://keith-wood.name/countdown.html under the tab Formats1 says.

I didn't manage yet to make it work. How to modify the code to get a unix timestamp as input and hide the days?

Standard timer

<script type="text/javascript">
$(function () {
    var austDay = new Date();
    austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
    $('#defaultCountdown').countdown({until: austDay});
    $('#year').text(austDay.getFullYear());
});

</script>

My try to have as input a unix timestamp (does not work)

<script type="text/javascript">
$(function () {
    var austDay = new Date();
    austDay = new Date(<?php echo $unixtimestamp; ?>*1000);
    $('#defaultCountdown').countdown({until: austDay});
    $('#year').text(austDay.getFullYear());
});

</script>

1 Answer 1

2

You can use the setTime() function:

var austDay = new Date();
austDay.setTime(<?php echo $unixtimestamp * 1000; ?>);

Edit: added * 1000 to go from unix timestamp to javascript timestamp...

Sign up to request clarification or add additional context in comments.

3 Comments

I tried it with no result but when I added *1000 it worked.
@JPampos Oops, sorry, you're right, unix timestamps are in seconds and javascript timestamps are in milliseconds...
Thanks for this, I managed to fix the second part from your reply.

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.