我使用此代码,但我不知道如何在所有国家/地区仅显示阿联酋标准时间。
<html>
<head></head>
<body>
<script>
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday",
"Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June",
"July","August","September","October","November","December")
document.write(dayarray[day]+", "+montharray[month]+" "+daym+", "+year)
</script>
</body>
</html>
这是我的代码,请建议我正确答案,谢谢。
see image for detail
最佳答案
在PHP中尝试使用date_default_timezone_set
函数,这很简单
<?php
date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('d-m-Y H:i:s');
?>
如果要在Java脚本中使用,请尝试以下操作
<script>
var d = new Date();
var localTime = d.getTime();
var localOffset = d.getTimezoneOffset() * 60000;
var utc = localTime + localOffset;
var offset = 4; //UTC of Dubai is +04.00
var dubai = utc + (3600000*offset);
var nd = new Date(dubai);
alert("Dubai time is " + nd.toLocaleString() + "<br>");
</script>
关于javascript - 如何在所有国家/地区中仅显示阿联酋标准时间,月份和年份,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34633073/