Javascript日期函数在不同的操作系统中返回不同的时区,例如返回"印度标准时间" Windows操作系统和" IST" 在mac系统中。我希望"印度标准时间"在所有操作系统中。
这是我的代码:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = Date();
</script>
</body>
</html>
结果 在Windows中:2017年2月14日星期二13:03:02 GMT + 0530(印度标准时间) 在mac系统:2017年2月14日星期二13:03:02 GMT + 0530(IST)
答案 0 :(得分:0)
尝试使用
<script>
document.getElementById("demo").innerHTML = new Date();
</script>
答案 1 :(得分:0)
-Doozie.wf.rerun.failnodes=true
答案 2 :(得分:0)
我建议你使用时刻js。如果您正在使用amd模块加载器,那么您可以执行以下操作:
require(["moment"],(m)=>{console.log(m().utcOffset(330).format())})
答案 3 :(得分:0)
问题评论中已经提到过。
Object.defineProperty(Date.prototype, "getTimezoneString", {
enumerable: false,
writable: true,
configurable: false,
value: function(){
var retval = "Z";
var offset = this.getTimezoneOffset() / 60;
switch (offset) {
case 14: retval = "M†"; break;
case 13.75: retval = ""; break;
case 13: retval = "M†"; break;
case 12.75: retval = "M"; break;
case 12: retval = "M"; break;
case 11: retval = "L"; break;
case 10.5: retval = "K†"; break;
case 10: retval = "K"; break;
case 9.5: retval = "I†"; break;
case 9: retval = "I"; break;
case 8.75: retval = "H*"; break;
case 8.5: retval = "H†"; break;
case 8: retval = "H"; break;
case 7: retval = "G"; break;
case 6.5: retval = "F†"; break;
case 6: retval = "F"; break;
case 5.75: retval = "E*"; break;
case 5.5: retval = "E†"; break;
case 5: retval = "E"; break;
case 4.5: retval = "D†"; break;
case 4: retval = "D"; break;
case 3.5: retval = "C†"; break;
case 3: retval = "C"; break;
case 2: retval = "B"; break;
case 1: retval = "A"; break;
case 0: retval = "Z"; break;
case -1: retval = "N"; break;
case -2: retval = "O"; break;
case -3: retval = "P"; break;
case -3.5: retval = "P†"; break;
case -4: retval = "Q"; break;
case -5: retval = "R"; break;
case -6: retval = "S"; break;
case -7: retval = "T"; break;
case -8: retval = "U"; break;
case -9: retval = "V"; break;
case -9.5: retval = "V†"; break;
case -10: retval = "W"; break;
case -11: retval = "X"; break;
case -12: retval = "Y"; break;
default: retval = "Z"; break;
}
return retval;
}
});
//https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
//more detail: https://www.timeanddate.com/time/zones/
var timezone = new Date().getTimezoneString();
document.querySelector("#date").innerHTML = timezone;
&#13;
<div id="date">
</div>
&#13;