开发者

How to display the current time continously in a different time zone?

开发者 https://www.devze.com 2023-01-18 23:26 出处:网络
I would like to display the current time continuously but in a different time zone? The following code will display the current time continuously.

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

Joe


This 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

0

精彩评论

暂无评论...
验证码 换一张
取 消