使用一个聊天框,在那里用raw获取消息时间,到目前为止,我得到了这个$msg_time = strtotime($row["date_time"]);
,它正确地显示了strtotime值。现在正在困惑如何用本地时区来显示这一点
服务器时区
<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('UTC');
echo date("m-d-Y", strtotime('2014-02-21')) . "timezone: " . date_default_timezone_get();
客户端时区
要显示时区的文件
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
<!-- javascript/jQuery -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<?php
session_start();
echo isset($_SESSION['time']) ? $_SESSION['time'] : "error";
?>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
var visitortime = new Date();
var visitortimezone = "GMT " + -visitortime.getTimezoneOffset() / 60;
$.ajax({
type: "POST",
url: "timezone.php?XDEBUG_SESSION_START=1",
data: 'time=' + visitortimezone,
success: function (data) {
}
});
});
</script>
</body>
</html>
timezone.php
<?php
session_start();
$_SESSION['time'] = $_POST['time'];