开发者

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

开发者 https://www.devze.com 2023-02-11 02:35 出处:网络
I would like to have a javascript date object having its time set according to the web server. <script type=\"text/javascript\">

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

<script type="text/javascript">

var date=new Date();

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

ale开发者_StackOverflowrt(date.toString()); //displays the date and time according to the timezone set on the client's computer

</script>

Is the above code reliable?

Many thanks to you all.


I think it's not.

Since Javascript's setTime() works with milliseconds and PHP's time() works with seconds.

You'll need to add some stuff to make it works ;) I'll let you find out what.

0

精彩评论

暂无评论...
验证码 换一张
取 消