I would like to display the current time continuously but in a different time zone?
The following code will display the current time continuously.
Can I update to get the time in a different time zone.?
<script type="text/javascript">
function ShowTime() {
var dt = new Date();
document.getElementById("<%= TextBox1.ClientID %>").value
= dt.toLocaleTimeString();
window.setTimeout("ShowTime()", 1000);
}
</script>
<asp:TextBox ID="Tex开发者_C百科tBox1" runat="server" CssClass="time"></asp:TextBox>
<script type="text/javascript">
// a startup script to put everything in motion
window.setTimeout("ShowTime()", 1000);
</script>
Please help
Thank you JoeThis article talks about how to calculate time in another timezone:
https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-6016329.html
The datejs library might be a good starting point. There's a getTimezoneOffset
method that gives you the time offset for a given timezone.
Also, consider using setInterval
instead of setTimeout
.
Convert date to timestamp and add the hours for the preffered timezone.
Convert tmestamp to date again.
var currentdate = 20101007163045
current timestamp= time(currentdate);
another timezone + 3 hours var expectedtimestamp=timestamp + time(3hrs)
expecteddate= date(expectedtimestamp).
This is algorithm. check your syntaxes
精彩评论