How to convert UTC datetime into many local timezones

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
 
J

Jerry Pisk

That doesn't answer anything. It's basically bad design in the framework and
you have to do it yourself. It gets very tricky if you want to handle
daylight saving time.

Jerry
 
B

Bert Hyman

In "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.

When you say "many clientside local timezones", do you mean many
individual clients, each of which may be in a different timezone, or do
you mean one client with a requirement to convert to one of many timzeones
which the user may select dynamically?

If it's the former, won't DateTime.ToLocalTime() and
DateTime.ToUniveralTime() work for you?

If the latter, I guess you'll have to maintain a table of timzezones and
offsets and do some DateTime.Add() and DateTime.Subtract() fiddling.
 
J

Jerry Pisk

Bert,

adding and substracting hours will not work, because of daylight saving
times.

Jerry
 
B

Bert Hyman

In "Jerry Pisk"
Bert,

adding and substracting hours will not work, because of daylight saving
times.

Sure it will work; it's just a little more complicated to figure out how
much to add or subtract :).

All you need is the TZ offset for each and every possible location on
earth and their rules for daylight savings time.

So for the original poster's sake, I hope his problem is represented by
the first case I presented, and not the second.

Othewise, good luck to him!
 
P

phuong

Hi all,

First, I thank you all for your replies!

DateTime.ToLocalTime() and DateTime.ToUniveralTime() do converting 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 (also
care about the daytlight saving in each client area) before showing 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

PS. I have found the way to do this by using javascript functions at client
side.
 
B

Bert Hyman

(e-mail address removed) (phuong) wrote in
What I want to do in my WEB application

Agh!

I'm sorry; I wandered in late and missed that very important
fact.
 

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

Top