How to convert UTC datetime into any local client timezone

  • Thread starter Thread starter phuong
  • Start date Start date
P

phuong

Hello,

I am developing a Web appplication using C# , ASP.NET.

All the datetimes stored in our database are UTC datetime.
How can I convert UTC datetime into many clientside local timezones.
and vice versa ie: to convert the local client timezone datetime back to
UTC datetime before saving it to database.

Any suggestion is very appreciated!


Thank in advance!

Phuong
 
Just a question here...

would it account for daylight savings so that we can show the local time???
 
Hi Martin,

Thanks for your reply. But what they tried to do in the example is not what
I want to do. That example has tried to convert datetime between the local
timezone of the SERVER machine (not the CLIENT machine) and the UTC
datetime.

What I want to do in my WEB application is let the user at the client side
enter a datetime (using calendar) Then, when the page postback to the server
side, the appplication have to know from which timezone the CLIENT is (note
that: this is a WEB app. There are a thousand of clients from the internet)
and then convert the entered datetime into UTC datetime before saving it
into database. Later when showing the UTC datetime retrieved from our
database, I want first it is converted to the local CLIENT timezone before
show it on the web UI.

Hope, that I have explained my problem clearly. If you need more info,
please feel free to ask.

Thank you very much!!!



Phuong
 
phoung as far as the client datetime is concerned, you can get the timezone
by using the following:
<script language="javascript">
function init()
{
var datNow = new Date();
/// e.g. -8 means the zone is UTC+8
/// e.g. 8 means the zone is UTC -8
/// the offset value is the value that is applied in hours to the
current datetime
/// in order to get the current UTC value
document.forms[0]["offset"].value = datNow.getTimezoneOffset();
}
</script>
<body onload="init();">
<form runat="server">
<input type="hidden" runat="server" id="offset" />
</form>
</body>

caveat
=====
1. If the client has the wrong settings, you will receive the wrong
settings.
 
Dear Devplayer04,

Thanks for your help. I have successfully converted from Client side
timezone datetime to UTC datetime, using getUTCDate, getUTCMonth,
getUTCFullYear, getUTCHour.....
These functions return UTC datetime with correct DAYLIGHT SAVINGS.

But I am still stuck in the reverse direction, ie. convert from UTC to any
client timezone datetime with a correct DAYLIGHT SAVING.
From the UTC offset I can get the local client datetime but I can not get a
correct datetime if it is in daylight saving period..

If you have any sugesstion, please share it with me. I am very appreciated
your help.

Thanks allot!!

Phuong


devplayer04 said:
phoung as far as the client datetime is concerned, you can get the timezone
by using the following:
<script language="javascript">
function init()
{
var datNow = new Date();
/// e.g. -8 means the zone is UTC+8
/// e.g. 8 means the zone is UTC -8
/// the offset value is the value that is applied in hours to the
current datetime
/// in order to get the current UTC value
document.forms[0]["offset"].value = datNow.getTimezoneOffset();
}
</script>
<body onload="init();">
<form runat="server">
<input type="hidden" runat="server" id="offset" />
</form>
</body>

caveat
=====
1. If the client has the wrong settings, you will receive the wrong
settings.


phuong said:
Hi Martin,

Thanks for your reply. But what they tried to do in the example is not what
I want to do. That example has tried to convert datetime between the local
timezone of the SERVER machine (not the CLIENT machine) and the UTC
datetime.

What I want to do in my WEB application is let the user at the client side
enter a datetime (using calendar) Then, when the page postback to the server
side, the appplication have to know from which timezone the CLIENT is (note
that: this is a WEB app. There are a thousand of clients from the internet)
and then convert the entered datetime into UTC datetime before saving it
into database. Later when showing the UTC datetime retrieved from our
database, I want first it is converted to the local CLIENT timezone before
show it on the web UI.

Hope, that I have explained my problem clearly. If you need more info,
please feel free to ask.

Thank you very much!!!



Phuong
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconformattingobjectsforspecificculture.asp
 
Back
Top