在PHP和javascript中使用time()和setTime()函数

bob*_*obo 3 javascript php datetime date utc

我想有一个javascript日期对象根据Web服务器设置其时间.

<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's computer

</script>
Run Code Online (Sandbox Code Playgroud)

以上代码是否可靠?

非常感谢大家.

Shi*_*ryu 5

我认为不是.

由于Javascript的setTime()工作时间为毫秒,而PHP的time()工作时间为秒.

你需要添加一些东西才能使它有效;)我会告诉你什么.