473,387 Members | 1,535 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,387 software developers and data experts.

Daylight Savings time

Is there a way to check if it is daylight savings or not via c#? I have
heard you can use System.Globalization?

Thanks - Drew
Nov 16 '05 #1
1 30108
There's an example in MSDN help

http://msdn.microsoft.com/library/de...classtopic.asp

// Example of selected TimeZone class elements.
using System;
using System.Globalization;

class TimeZoneDemo
{
static void Main( )
{
const string dataFmt = "{0,-30}{1}";
const string timeFmt = "{0,-30}{1:yyyy-MM-dd HH:mm}";

Console.WriteLine(
"This example of selected TimeZone class " +
"elements generates the following \n" +
"output, which varies depending on the " +
"time zone in which it is run.\n" );

// Get the local time zone and the current local time and year.
TimeZone localZone = TimeZone.CurrentTimeZone;
DateTime currentDate = DateTime.Now;
int currentYear = currentDate.Year;

// Display the names for standard time and daylight saving
// time for the local time zone.
Console.WriteLine( dataFmt, "Standard time name:",
localZone.StandardName );
Console.WriteLine( dataFmt, "Daylight saving time name:",
localZone.DaylightName );

// Display the current date and time and show if they occur
// in daylight saving time.
Console.WriteLine( "\n" + timeFmt, "Current date and time:",
currentDate );
Console.WriteLine( dataFmt, "Daylight saving time?",
localZone.IsDaylightSavingTime( currentDate ) );

// Get the current Coordinated Universal Time (UTC) and UTC
// offset.
DateTime currentUTC =
localZone.ToUniversalTime( currentDate );
TimeSpan currentOffset =
localZone.GetUtcOffset( currentDate );

Console.WriteLine( timeFmt, "Coordinated Universal Time:",
currentUTC );
Console.WriteLine( dataFmt, "UTC offset:", currentOffset );

// Get the DaylightTime object for the current year.
DaylightTime daylight =
localZone.GetDaylightChanges( currentYear );

// Display the daylight saving time range for the current year.
Console.WriteLine(
"\nDaylight saving time for year {0}:", currentYear );
Console.WriteLine( "{0:yyyy-MM-dd HH:mm} to " +
"{1:yyyy-MM-dd HH:mm}, delta: {2}",
daylight.Start, daylight.End, daylight.Delta );
}
}

/*
This example of selected TimeZone class elements generates the
following
output, which varies depending on the time zone in which it is run.

Standard time name: Pacific Standard Time
Daylight saving time name: Pacific Standard Time

Current date and time: 2003-05-08 11:10
Daylight saving time? True
Coordinated Universal Time: 2003-05-08 18:10
UTC offset: -07:00:00

Daylight saving time for year 2003:
2003-04-06 02:00 to 2003-10-26 02:00, delta: 01:00:00
*/

Nov 16 '05 #2

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

Similar topics

3
by: Bathroom_Monkey | last post by:
For posterity's sake, here is an algorithm I created to take a GMT time and convert it to U.S. central time, accounting for daylight saving time. Note: this algorithm can be modified to work for...
2
by: hourang | last post by:
ok im getting tired of looking for an answer and coming up short with scripts that dont work. i have a application that uses GMT for all its times and needs the clients timeoffset for showing the...
10
by: Marc Pelletier | last post by:
Hello, I am writing an application that does some simple astronomical calculations. One of the variables I need is the number of hours passed in this year. I've written the following function ...
1
by: Daniel | last post by:
Is there a patch for congress new 2007 daylight savings time change? http://geography.about.com/cs/daylightsavings/a/dst.htm This could have economic impact like y2k did. Is there a patch for...
6
by: Daniel | last post by:
Do any microsoft buildtime dependancies C#/C/c++/VB/etc. need to be updated for the 2007 policy on daylight savings time? I know the OS needs to be updated but I care now about C libraries, .net...
6
by: sugapablo | last post by:
I have an old machine running Mandrake 9.2 and PHP 4.3.1 hosting several websites. With the coming changes to daylight savings time in March 2007, what are my options in correcting the current...
3
by: J | last post by:
Hello. Our webserver is running Windows 2000 Server iis5 and was wondering if anyone knew if the new Daylight Savings Time rule will affect any classic ..asp pages? I think I'm mainly concerned...
3
by: mmuras | last post by:
I did not see any discussions / threads for this but if there is one please let me know: -First, I am one of only two individuals within my company's IT Dept. -We have a Windows Server 2003 R2...
37
by: David T. Ashley | last post by:
I have Red Hat Enterprise Linux 4. I was just reading up about UTC and leap seconds. Is it true on my system that the Unix time may skip up or down by one second at midnight when there is a...
0
by: =?Utf-8?B?S2VsbHk=?= | last post by:
Each fall and winter I deal witht he same problem. When the daylight savings time comes into effect the time stamp for files on my external portable hard drive are 1 hour out from the time stamps...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.