2012-12-07 69 views
1

我想,以顯示不同的時區股票時鐘。當我看着各地的網絡,它看起來像它在JavaScript花費數偏移量(例如5.5小時)。但是,我們所得到的gmtformat的方式是+05:30在PHP我正努力在飼料給JavaScript函數。有沒有我可以用來轉換的功能?格林尼治標準時間格式整數格式

/*CLOCK CODE IN JAVASCRIPT*/ 
function startclock(field, timediff, newOrRepeat) 
{ 
    var clockAction=newOrRepeat; 
if (timediff=="") {$(field).html("-------");return false;} 
    /****THERE ARE MORE STUFF IN BETWEEN AND AFTER WHICH IS NOT RELEVANT TO OFFSET****/ 
var secondsDiff=0; 
var secondsTimeZone = 0; 
//calculate the difference in time set by both the timezone as well as the DST 
secondsTimeZone = parseInt(timediff); 


if ($("input[name='daylight']:checked").val()=="on" && $(field).siblings("#isDaylight").val()=="no") 
    secondsDiff=secondsTimeZone + 3600; 
else if ($("input[name='daylight']:checked").val()=="off" && $(field).siblings("#isDaylight").val()=="yes") 
    secondsDiff=secondsTimeZone - 3600; 
else 
    secondsDiff = secondsTimeZone; 

var thetime=new Date(); 

thetime.setUTCSeconds(parseInt(thetime.getUTCSeconds())+parseInt(secondsDiff)); 
var nhours=thetime.getUTCHours(); 
var nmins=thetime.getUTCMinutes(); 
var nsecn=thetime.getUTCSeconds(); 

} 

我得到gmt格式,直接從我傳遞給這個函數的PHP。

+0

Whathaveyoutried?轉換成什麼。給出例子和代碼。 – PitaJ

+0

我想轉換+05:30〜5.5。 –

+0

你有後提取整數值「:」如果不是零,然後把它在60然後將結果後「:」 – SaidbakR

回答

1
function convert_time($time){ 
    $parts = explode(':', $time); 
    return $parts[0] + number_format($parts[1]/60, 2); 
} 
+0

我想通了這一點,但我一直在尋找一個內置的PHP函數或JavaScript功能。儘管如此,它的工作。 謝謝 –

相關問題