N
N
Nikolay Firsov2015-11-13 02:37:02
PHP
Nikolay Firsov, 2015-11-13 02:37:02

How to bring data () in php and js to a single format?

jsfiddle.net/c0o2qpan Does
n't work there because of the lines
var day = <? echo $Day ?>;
...
var hour=<? echo $hour ?>;
But in general the script is working.
How can I set a value for var now so that date is taken from php in the same format as date in js and the script does not break? I don’t understand languages ​​at all, I found a working timer script and I’m trying to attach time synchronization to the server to it.

Through AJAX it is also possible, I found ready-made examples, but there you need to create a separate file with a php script, I would like everything to be on one page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
profesor08, 2015-11-13
@Niolay_Firsov

Probably so:

<center>
  <div id="countdown"></div>
  <span id="span">remain</span>
</center>
CountDownTimer('<?php echo date("m/d/Y H:i A", time()); ?>', 'countdown');

function CountDownTimer(dt, id)
    {
        var end = new Date(dt);
        var _second = 1000;
        var _minute = _second * 60;
        var _hour = _minute * 60;
        var _day = _hour * 24;
        var timer;

        function showRemaining() {
            var now = new Date();
            var distance = end - now;
            if (distance < 0) {

                clearInterval(timer);
                document.getElementById(id).innerHTML = 'EXPIRED!';

                return;
            }
            var days = Math.floor(distance / _day);
            var hours = Math.floor((distance % _day) / _hour);
            var minutes = Math.floor((distance % _hour) / _minute);
            var seconds = Math.floor((distance % _minute) / _second);

            document.getElementById(id).innerHTML = days + 'days ';
            document.getElementById(id).innerHTML += hours + 'hrs ';
            document.getElementById(id).innerHTML += minutes + 'mins ';
            document.getElementById(id).innerHTML += seconds + 'secs';
        }

        timer = setInterval(showRemaining, 1000);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question