Reputation: 1550
I have a countdown script that allows me to count down to a certain time.
The time is calculated in milliseconds.
I use a website to calculate the milliseconds to where I want the countdown to end, but I think this comes with a problem.
If I do a test for a minute it runs behind (my computer hits the minute mark before the script does). This is probably because the milliseconds are calculated from the internal clock. If my clock is set different the milliseconds don't work right. (I hope)
So I thought I let the script calculate the milliseconds. This way it doesn't matter on what server the script runs it always takes the time from the internal clock of that server.
I have no idea how to calculate this. And this is where you come in :-) I hope anybody can help me out here.
<script type="text/javascript">
$(function(){
FlipClock.Lang.Custom = { days:'Dagen', hours:'Uren', minutes:'Minuten', seconds:'Seconden' };
var opts = {
clockFace: 'DailyCounter',
countdown: true,
language: 'Custom'
};
var countdown = 1440077820 - ((new Date().getTime())/1000); // from: 09/19/2015 07:19 pm +0200
countdown = Math.max(1, countdown);
$('.clock-builder-output').FlipClock(countdown, opts);
});
</script>
The problem is that I don't really understand JS....
M.
Upvotes: 1
Views: 461
Reputation: 1890
I've modified your example. This will countdown in seconds to August (months enumerate from 0) 30th 2015, at 3:15
<script type="text/javascript">
$(function(){
FlipClock.Lang.Custom = { days:'Dagen', hours:'Uren', minutes:'Minuten', seconds:'Seconden' };
var opts = {
clockFace: 'DailyCounter',
countdown: true,
language: 'Custom'
};
var dateTo = new Date(2015, 07, 30, 3, 15, 0);
var countdown = Math.round((dateTo.getTime() - new Date().getTime()) / 1000);
$('.clock-builder-output').FlipClock(countdown, opts);
});
</script>
Upvotes: 1