Using time () and setTime () functions in PHP and javascript

I would like the javascript date object to have its time set according to the web server.

<script type="text/javascript">

var date=new Date();

date.setTime(<?php echo time() ?>);

alert(date.toString()); //displays the date and time according to the timezone set on the client computer

</script>

Is this code reliable?

Many thanks to all of you.

+3
source share
1 answer

I think not.

Because JavascriptsetTime() works with milliseconds and PHPtime() works with seconds.

You need to add something to make it work;) I will let you know that.

+5
source

Source: https://habr.com/ru/post/1792222/


All Articles