Link to home
Start Free TrialLog in
Avatar of Blessed7777
Blessed7777

asked on

Display different time zones on web page

Would someone please advise how to display a time for different timezones using <%Response.Write(System.DateTime.Now)%>.  It seems like it would be something really easy, yet I can find nothing online for this specific request.
<%Response.Write(System.DateTime.Now)%>

Open in new window

Avatar of GiftsonDJohn
GiftsonDJohn
Flag of India image

This code sample works only for .net version 3.5
DateTime dt = DateTime.Now.ToUniversalTime();
        StringBuilder builder = new StringBuilder();
 
        foreach (TimeZoneInfo tzi in TimeZoneInfo.GetSystemTimeZones())
        {
            builder.Append(tzi.StandardName + " : " + dt.Add(tzi.BaseUtcOffset).ToString());
            builder.Append("<br/>");
        }
 
        Label1.Text = builder.ToString();

Open in new window

Avatar of Blessed7777
Blessed7777

ASKER

This would work if I needed to pick up one user's time zonezone.  But I actually need to display 4 different time zones on the page.  We have employees in 4 different time zones sharing the app and working together in it.  One for Central, one for mountain, one for pacific and one for eastern.  Is there an insert for after .now that will give these values?  Ie:  something like <%Response.Write(System.DateTime.Now.EDT)%> to represent eastern time.

Thank youfor your assistance with this
There is no function which supports the format you are looking for. We have to calculate the time by adjusting UTC offset from UTC time.

Do you want to display the time as clock like

Central         Mountain          Pacific         Eastern
 xx:xx             xx:xx             xx:xx            xx:xx

and keeps on refreshing every minute?
Hi GiftsonDJohn, yes that is exactly what i am looking to do.  Any suggestions you have would be great.
ASKER CERTIFIED SOLUTION
Avatar of GiftsonDJohn
GiftsonDJohn
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh!  Very cool :)  I am going to followed this example and it worked like a charm.  Thanks for your help with this.  I'm increasing the points to 500 as you went the extra mile.