日期:2014-05-17  浏览次数:20595 次

PHP的时间戳让JS显示,显示不正确!
HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>时间</title>
</head>

<body>
<script type="text/javascript">
var time = new Date(<?php echo(time());?> * 1000);
alert(time.getFullYear() + "-" + time.getMonth() + "-" + time.getDay() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds());
</script>
</body>
</html>



------解决方案--------------------
HTML code
[code=PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html, charset=utf-8" />
<title>时间</title>
</head>

<body>
<?php echo date('Y-m-d H:i:s');?><br />
<script type="text/javascript">
var time = new Date(<?php echo(time());?>*1000);
document.write(time.getFullYear() + "-" + (time.getMonth()+1) + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds());
</script>
</body>
</html>