473,383 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

IsDaylightSavingTime Not Working Correctly

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(c allDate))
{
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

Nov 16 '05 #1
2 6508
"MJR" <mi******@gmail.com> wrote in
news:11**********************@f14g2000cwb.googlegr oups.com:
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(c allDate))
{
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...tetimecode.asp

or

http://tinyurl.com/6xkdz

You can see what the DST settings are for your current timezone by
calling TimeZone.CurrentTimeZone.GetDaylightChanges(callDa te.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.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2
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_2...-Correctly.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Don Leckie | last post by:
Hi, I'm upgrading our software from JDK 1.3.1_03 to JDK 1.4.2_07 and I'm having trouble with ComponentOrientation.RIGHT_TO_LEFT working correctly in a JScrollPane. One of my windows has a...
2
by: Kamyk | last post by:
Hello all! Could you tell me where is the error on the below code, because the script is sometimes working correctly and sometimes is not working correctly. I want my new window with picture...
17
by: Jonathan Burd | last post by:
Greetings everyone, Reading about the int64_t types added by C'99, I decided to implement a 64-bit version of atoi for my own library. However, for the test number provided, it isn't doing what...
0
by: mikejrae | last post by:
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...
10
by: Scott Richards | last post by:
Hi I am getting a exception while using a datareader here is the code Me.SqlConnection1.Open() Me.SqlReservationCheck.Parameters("@Ref").Value = Ref Dim Reader As SqlClient.SqlDataReader = _...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
3
by: doomsday123 | last post by:
Will private bool IsDST(DateTime d) { return System.TimeZone.IsDaylightSavingTime(d, System.TimeZone.CurrentTimeZone.GetDaylightChanges(d.Year)); } in .NET 1.1 return the same thing as this...
1
by: Mark B | last post by:
This is my first try at using AJAX. I want the calendars to be enabled if the user checks CheckBox1. It works OK for a normal all page refresh but once I introduced the AJAX code it stopped...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.