How can I display local time from UTC?

G

Guest

I have a SQL table that stores the UTC time for a column, I then want to
display the UTC time to the user in their local time.

My approach is to have the user set their time zone via their user profile.
Then to use that setting to convert the UTC date/time to the users local time.

I am using C# via ASP.Net. Any suggestions? I thought I had found
something using the CultureInfo class and Response.UserLanguages, however,
this always displays the same time regardless if I am on Eastern time or
Pacific time.

Any help would be greatly appreciated.
 
B

Bruce Barker

you will have to use javascript date function in a sniffer page.


<form method=post action='myRealFirstPage.aspx'>
<input type='hidden' name='dateOffset'>
<script>
document.forms[0].dateOffset.value = (new Date).getTimezoneOffset();
document.forms[0].submit();
</script>
</form>

-- bruce (sqlwork.com)
 
G

Guest

Thanks, I was looking for a server side solution. Since JavaScript being
turned on is no guarantee.
 
G

Guest

Do you want to automatically fetch the users timezone (form the windows
environment), or do you want to use the timezone (e.g. UTC+1) information
from the users profile?
 
G

Guest

If it was technically possible without the user being able to turn off the
code I would like to get it from the user's environment (the less the user
has to do the better), however, if not possible then I will have the user set
up their profile to tell me what their time zone is.

After I figured out this issue, I still need to figure out daylight savings
time issues throughout the world in order to display the time appropriately.
 
G

Guest

I do not think it is possible get this information based on e.g. CultureInfo.
Then I see only two alternatives to solve this (without using javascripts).

1. Ask the user to save/choose their timezone in +/- hours or by "timezone
name" ("Mountain Daylight Time", "Mountain Standard Time", "Canberra,
Melborne, Sydney", etc.), or by abbreviations see:
(http://www.worldtimezone.com/wtz-names/timezonenames.html). But this is not
a good solution for the user...

2. Write a few server side code lines that sends the web users IP address to
http://www.showmyip.com/simple/?ip=<the ip address here>&get=timezone or
another site that locates the location and timezone of a IP address.
Unfortunately you have to subscribe for the service at www.showmyip.com, but
there may be a free service available also.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top