<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>
获取本地计算机时间。 我想在javascript中获得IST时间。
答案 0 :(得分:14)
以下内容允许您将当地时间转换为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>")