在网站JS上显示GMT + 1次

时间:2017-03-27 13:46:17

标签: javascript html

我正在尝试将GMT + 1的时间显示在我的网站上。

我发现并提供了一些工作正常的代码,但现在它似乎无法正常工作。

任何想法为什么或者你知道更好的方法吗?

由于

<script type="text/javascript">
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh)
}
tday=new Array("Sun","Mon","Tues","Wed","Thurs","Fri","Sat");
tmonth=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function display_ct() {
var strcount
var d1= new Date();
var x = new Date()
x.setHours(x.getHours() + 1);

var nday2=x.getDay();
var nmonth2=x.getMonth();
var ndate2=x.getDate();
var nyear2=x.getFullYear();
var nsec2=x.getSeconds();
var nhour2=x.getHours();

var nmin=d1.getMinutes();
if(nmin<=9)
nmin="0"+nmin;

var x1=x.toUTCString();// changing the display to UTC string
document.getElementById('ct').innerHTML = ""+tday[nday2]+", "+ndate2+" "+tmonth[nmonth2]+", "+nyear2+" | "+nhour2+":"+nmin+":"+nsec2+" GMT +1";
tt=display_c();
}
</script>



<span id="ct"></span>

2 个答案:

答案 0 :(得分:1)

var a = new Date();
new Date(+a - a.getTimezoneOffset() + 3600000).toISOString().split(".")[0]; 

答案 1 :(得分:0)

上面的代码没有错。似乎它是导致问题的页面上的其他内容。

<body onload=display_ct();>
<span id="ct"></span>
</body>

function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh)
}
tday=new Array("Sun","Mon","Tues","Wed","Thurs","Fri","Sat");
tmonth=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function display_ct() {
var strcount
var d1= new Date();
var x = new Date()
x.setHours(x.getHours() + 1);

var nday2=x.getDay();
var nmonth2=x.getMonth();
var ndate2=x.getDate();
var nyear2=x.getFullYear();
var nsec2=x.getSeconds();
var nhour2=x.getHours();

var nmin=d1.getMinutes();
if(nmin<=9)
nmin="0"+nmin;

var x1=x.toUTCString();// changing the display to UTC string
document.getElementById('ct').innerHTML = ""+tday[nday2]+", "+ndate2+" "+tmonth[nmonth2]+", "+nyear2+" | "+nhour2+":"+nmin+":"+nsec2+" GMT +1";
tt=display_c();
}

example js fiddle of the code