use*_*341 2 javascript timezone
我想在Javascript中设置不同的时区.当前它显示本地机器或客户端的PC日期/时区的日期和时区.
问候,
Javascript是一种客户端语言,不会以这种方式与服务器交互.您需要从服务器端平台获取该数据.
这里有一些PHP代码来获取您正在寻找的数据.您需要将其放入页面并将结果回显到JS变量中....
<?php
$date = new DateTime(null, new DateTimeZone('Europe/London'));
$tz = $date->getTimezone();
$tzone = $tz->getName();
?>
<script type="text/javascript">
var timeZone='<?php echo $tzone ?>';
</script>
Run Code Online (Sandbox Code Playgroud)
....或保持PHP页面分开,并使用AJAX获取数据
getTimeZone.php
<?php
$date = new DateTime(null, new DateTimeZone('Europe/London'));
$tz = $date->getTimezone();
echo $tz->getName();
?>
Run Code Online (Sandbox Code Playgroud)
JS
var timeZone=null;
$.get('getTimeZone.php', function(result){
timeZone=result;
}, 'html');
//I know this is jQuery, not JS, but you get the idea.
Run Code Online (Sandbox Code Playgroud)