Display date in EST/EDT from an Arizona server

  • Thread starter Thread starter Max
  • Start date Start date
M

Max

I need to display time as Eastern Time. The problem I'm having is that our server is in Arizona where there is no Daylight Savings
time. That means half the year I need to add 2 hours to the time and other other half I need to add 3 hours. I was trying to use
IsDaylightSavingTime by passing the local date time but it is never daylight savings so it always returns false. Is there a way to
force the method to look at the time as ET or is there any other way around this?

This always returns false....

if ( System.TimeZone.IsDaylightSavingTime(DateTime.Now) )
{
lblCurrentDate.Text = DateTime.Now.AddHours(2).ToString("D");
}
else
{
lblCurrentDate.Text = DateTime.Now.AddHours(3).ToString("D");
}
 
I need to display time as Eastern Time. The problem I'm having is that our server is in Arizona where there is no Daylight Savings
time. That means half the year I need to add 2 hours to the time and other other half I need to add 3 hours. I was trying to use
IsDaylightSavingTime by passing the local date time but it is never daylight savings so it always returns false. Is there a way to
force the method to look at the time as ET or is there any other way around this?

This always returns false....

if ( System.TimeZone.IsDaylightSavingTime(DateTime.Now) )
{
lblCurrentDate.Text = DateTime.Now.AddHours(2).ToString("D");
}
else
{
lblCurrentDate.Text = DateTime.Now.AddHours(3).ToString("D");
}

I don't know if you tried this or not, but it seems to me you could do
something like this:

When you get the time from the server use DateTime.UTC. In NYC use
DateTime.ToLocalTime(). I think when you convert it in NYC you will
get the local time of the computer in NYC. I haven't tested this, but
it think it will work.

DateTime localTime = serverDateTime.ToLocalTime();

As a comment; It has always been my belief that when you are keeping
time records that are important, they should be in UTC. You can
always convert them back to local time when you need to.

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
 
As Max said, I would keep all dates on the server in UTC format and convert
to local time on the clients. If you can't make that change, I have a local
to local time converter that respects TZ in c# I can post.

--
William Stacey [MVP]

| I need to display time as Eastern Time. The problem I'm having is that
our server is in Arizona where there is no Daylight Savings
| time. That means half the year I need to add 2 hours to the time and
other other half I need to add 3 hours. I was trying to use
| IsDaylightSavingTime by passing the local date time but it is never
daylight savings so it always returns false. Is there a way to
| force the method to look at the time as ET or is there any other way
around this?
|
| This always returns false....
|
| if ( System.TimeZone.IsDaylightSavingTime(DateTime.Now) )
| {
| lblCurrentDate.Text = DateTime.Now.AddHours(2).ToString("D");
| }
| else
| {
| lblCurrentDate.Text = DateTime.Now.AddHours(3).ToString("D");
| }
|
 

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

Back
Top