I built a PHP function that returns a future value in timestamp format. With that, I tried in script to get the countdown from that timestamp. Example: 1646435355 – 1646435055 = 300 seconds. I know that function “time()” of PHP return values in “seconds”, and javascript read on milliseconds, but, the question is: “How convert seconds that return of PHP function time() in milliseconds”? I read the docs of “moment.js” and find a line that talk about “unix” on function moment, but, i try this and dont work. You can help?
var duration = moment.duration(<?php echo $timerCount; ?> * 1000, 'milliseconds');
var interval = 1000;
setInterval(function(){
duration = moment.duration(duration.asMilliseconds() - interval, 'milliseconds');
$('#time').text(moment(duration.asMilliseconds()).format('h:mm:ss'));
if(duration.asSeconds() <=0) {
window.location.replace(window.location.pathname + window.location.search + window.location.hash);
}
}, interval);
$timerCount is time()+5 minutes. And… Yes, i changed “milliseconds” to “seconds” and etc and nothing works.