IsDaylightSavingTime Not Working Correctly

M

MJR

I live in Arizona. We of course do not change for DST. All of the
data that is inserted into our database is in Arizona time. My client
wants me to display the Time Zone the record was inserted in relation
to Eastern Time. So all of the dates should be displayed as either PST
or MST depanding on the time of the year.

I am trying to use IsDaylightSavingTime to find out if the date in the
database was inserted during DST. The code for my if condition is:

if(TimeZone.CurrentTimeZone.IsDaylightSavingTime(callDate))
{
e.Item.Cells[2].Text = e.Item.Cells[2].Text + " PST";
}
else
{
e.Item.Cells[2].Text = e.Item.Cells[2].Text + " MST";
}

No matter if 'callDate' is 1/5/2005 or 7/5/2005 IsDaylightSavingTime
always returns false. I even tried changing my local box to Pacific
Timezone but it made no difference.
Is there something I am missing?

Thanks in advance,


Mike
 
C

Chris R. Timmons

I live in Arizona. We of course do not change for DST. All of
the data that is inserted into our database is in Arizona time.
My client wants me to display the Time Zone the record was
inserted in relation to Eastern Time. So all of the dates should
be displayed as either PST or MST depanding on the time of the
year.

I am trying to use IsDaylightSavingTime to find out if the date
in the database was inserted during DST. The code for my if
condition is:

if(TimeZone.CurrentTimeZone.IsDaylightSavingTime(callDate))
{
e.Item.Cells[2].Text = e.Item.Cells[2].Text + " PST";
}
else
{
e.Item.Cells[2].Text = e.Item.Cells[2].Text + " MST";
}

Mike,

You may want to read this:

http://msdn.microsoft.com/library/en-us/dndotnet/html/datetimecode.asp

or

http://tinyurl.com/6xkdz

You can see what the DST settings are for your current timezone by
calling TimeZone.CurrentTimeZone.GetDaylightChanges(callDate.Year).
This returns a DaylightTime instance, and its Delta, Start and End
properties will tell you if .Net is detecting your DST settings
correctly.
No matter if 'callDate' is 1/5/2005 or 7/5/2005
IsDaylightSavingTime always returns false. I even tried changing
my local box to Pacific Timezone but it made no difference.
Is there something I am missing?

Did you restart your application after changing timezones? Using
Reflector to examine the CurrentTimeZone property, it only gets
the current time zone once when it's first called. It doesn't
detect a change in time zones.
 
J

John Greiner

Aside from the code, I think there is an erroneous assumption above -- all times would not be either PST or MST.

If I am sitting in California (which I happen to be doing), a few minutes ago it was 5:00 PM PDT. Four weeks ago (on 3/25), the time would've been 5:00 PM PST. When DST is active, then you are in Daylight Time. When DST is not active, you are in Standard Time. In Arizona, you are always on Standard time.

You can avoid that by leaving out the middle letter -- just call it "PT" or "Pacific Time" and "MT" or "Mountain Time" -- not sure if the abbreviations are formally used though.



From http://www.developmentnow.com/g/36_2005_1_0_0_41263/IsDaylightSavingTime-Not-Working-Correctly.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
 

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