views:

41

answers:

4

Hi,

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="TextBox1" 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

A: 

This article talks about how to calculate time in another timezone:

http://articles.techrepublic.com.com/5100-10878_11-6016329.html

Jud Stephenson
A: 

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.

Ondrej Tucny
A: 

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

zod
A: 

The date object can give the time in milliseconds since the epoch, so you just have to add or subtract the timezone.

function ShowTime() {
   var now = new Date( );
   var tz = 60*60*1000;
   var dt = new Date( now.valueOf()+ tz );
   document.getElementById("<%= TextBox1.ClientID %>").value =
       dt.toLocaleTimeString();
}

window.setInterval(ShowTime, 1000);

However, remember that toLocalTimeString converts the UTC time to the time zone that the users client is set to (you can find out with getTimezoneOffset()).

Consider using toTimeString instead (you can slice of the parts of the string that you want to keep)

And, also, use setInterval instead of setTimeout.

some