2014-05-08 08:01
浏览 21


I have the following Code -

<!DOCTYPE html>
function startTime() {
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('txt').innerHTML = h+":"+m+":"+s;
    var t = setTimeout(function(){startTime()},500);

function checkTime(i) {
    if (i<10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;

<body onload="startTime()">

<div id="txt"></div>


This code was refrenced from w3schools. But this code takes time from our system. But I want a javascript or server side method in PHP in which I can show UK time at the top of my page. It is easy to do so If I change the timezone to UK time in my config file but I want India time everywhere except that clock at the top of the page.

图片转代码服务由CSDN问答提供 功能建议

我有以下代码 -

 &lt;!DOCTYPE  html&gt; 
&lt; html&gt; 
&lt; head&gt; 
&lt; script&gt; 
function startTime(){
 var today = new Date(); 
 var h = today.getHours(); 
 var m = today  .getMinutes(); 
 var s = today.getSeconds(); 
m = checkTime(m); 
s = checkTime(s); 
 document.getElementById('txt')。innerHTML = h +“:”+  m +“:”+ s; 
 var t = setTimeout(function(){startTime()},500); 
function checkTime(i){
 if(i&lt; 10){i =“  0“+ i};  //在数字前添加零&lt;  10 
&lt; / script&gt; 
&lt; / head&gt; 
&lt; body onload =“startTime()”&gt; 
&lt; div id =“txt”&gt;&lt;  ; / div&gt; 
&lt; / body&gt; 
&lt; / html&gt; 

此代码来自w3schools。 但是这段代码需要我们系统的时间。 但我想在PHP中使用javascript或服务器端方法,我可以在页面顶部显示英国时间。 很容易这样做如果我在配置文件中将时区更改为英国时间,但除了页面顶部的时钟之外,我希望印度时间到处都是。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • douyan9417 2014-05-08 08:03

    Simply use getUTCDate or toUTCString

    var d = new Date(); // local date
    var n = d.getUTCDate(); // utc date

    to get full date string

    var d = new Date(); 
    var n = d.toUTCString();

    Demo --> http://jsfiddle.net/gPRBH/

    解决 无用
    打赏 举报

相关推荐 更多相似问题