471,325 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Display date in EST/EDT from an Arizona server

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");
}

Jan 31 '06 #1
2 3254
On Tue, 31 Jan 2006 16:06:35 -0500, "Max" <ma******@yahoo.com> wrote:
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
Feb 1 '06 #2
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]

"Max" <ma******@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
| 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");
| }
|
Feb 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Stupidgirl | last post: by
3 posts views Thread by Need Top Programmer | last post: by
2 posts views Thread by Benedict Teoh | last post: by
3 posts views Thread by Jim in Arizona | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.