Jerald.Net
A little VB.Net, SQL, and whatever else comes to mind...

Determining Day Lights Savings for Time Zones in ASP.Net

I needed to determine what the real TimeZone (CST vs CDT) was for my blog application. So here is what I came up with:

// instantiate a DateTime Object
DateTime dT = DateTime.Now;

// create a string to hold the full date and time
string pubDate = dT.ToLongDateString() + " " + dT.ToShortTimeString();

// determine if daylights savings and add the appropriate TimeZone
if(TimeZone.CurrentTimeZone.IsDaylightSavingTime(dT))
 {
     pubDate += " CDT";
  }

        else
        {
            pubDate += " CST";
        }

Granted I am really cheating and not using the full capabilities of the DateTime Class. But time is of the essence and I needed working code without a lot of testing to get the "right code".


Posted Apr 11 2005, 11:34 AM by Jerald Carter
Filed under:
© Jerald Carter 1999 - 2008
Powered by Community Server (Non-Commercial Edition), by Telligent Systems