2014-03-02 32 views
0
<script type="text/javascript"> 
<!-- 
var currentTime = new Date() 
var hours = currentTime.getHours() 
var minutes = currentTime.getMinutes() 

if (minutes < 10) 
minutes = "0" + minutes 

document.write("<b>" + hours + ":" + minutes + " " + "</b>") 
//--> 
</script> 

獲取本地comupter時間。 我想在JavaScript中獲得IST時間。在javascript中獲取IST時間

+1

你只能訪問到客戶方的計算機時鐘,你有什麼期待得到什麼? – adeneo

+0

您必須將當地時間轉換爲UTC,然後爲ITC添加偏移量 –

+0

我不知道該怎麼做,請舉例說明。 – user3371310

回答

9

下面將讓你轉換當地時間IST時間:

var currentTime = new Date(); 

var currentOffset = currentTime.getTimezoneOffset(); 

var ISTOffset = 330; // IST offset UTC +5:30 

var ISTTime = new Date(currentTime.getTime() + (ISTOffset + currentOffset)*60000); 

// ISTTime now represents the time in IST coordinates 

var hoursIST = ISTTime.getHours() 
var minutesIST = ISTTime.getMinutes() 

document.write("<b>" + hoursIST + ":" + minutesIST + " " + "</b>") 
+0

謝謝你... :) – user3371310

+0

謝謝,邁克,它爲我工作。 –