tags:

views:

14

answers:

1

Pl help me. I'm saving the date in UTC format. while displaying it, i'm converting it to local time. but it is displaying server time. How can i display the date by identifying the client timezone?

+1  A: 

I would venture a guess here that you are doing the conversion in C# code as part of an ASP.NET website.

Converting to local time converts to the local time of the machine where the code is actually executing. Thus, when you convert to local time, you are converting to the local timezone of your server machine, not the client machine.

To convert to the client local time, you need to know the local timezone of the client machine. Unfortunately, the standard ASP.NET HttpRequest does not include that information (mostly because the HTTP protocol does not specify a standard way for the client HTTP agent to pass its local timezone to the HTTP server). Multiple people have come with various solutions about this problem; here's one recent blog post about Handling TimeZone Information In ASP.NET that can help you.

Franci Penov
thanks for your reply.. Actually i tried with javascript as you said, it is working fine. Here i've a problem with using javascript.I'm able to get the client timezoneoffset and putting it into one static variable and adding that to the utc date of Last Viewed Info to get the client time info. unfortunately body onload is firing ofter page_load event. In page_load itself i need to display the date to the user. In our scenario, if we refresh the page then it is getting displayed properly.
stackuser1
please help me... if u have any info on it.
stackuser1
Instead of doing a full page refresh, you can fire a small piece of javascript to make an AJAX call to your server to get the updated date.
Franci Penov