473,566 Members | 2,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Globaliz ation?

Thanks - Drew
Nov 16 '05 #1
1 30132
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.Globaliz ation;

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

Console.WriteLi ne(
"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.Curren tTimeZone;
DateTime currentDate = DateTime.Now;
int currentYear = currentDate.Yea r;

// Display the names for standard time and daylight saving
// time for the local time zone.
Console.WriteLi ne( dataFmt, "Standard time name:",
localZone.Stand ardName );
Console.WriteLi ne( dataFmt, "Daylight saving time name:",
localZone.Dayli ghtName );

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

// Get the current Coordinated Universal Time (UTC) and UTC
// offset.
DateTime currentUTC =
localZone.ToUni versalTime( currentDate );
TimeSpan currentOffset =
localZone.GetUt cOffset( currentDate );

Console.WriteLi ne( timeFmt, "Coordinate d Universal Time:",
currentUTC );
Console.WriteLi ne( dataFmt, "UTC offset:", currentOffset );

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

// Display the daylight saving time range for the current year.
Console.WriteLi ne(
"\nDaylight saving time for year {0}:", currentYear );
Console.WriteLi ne( "{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
3654
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 any other U.S. timezone by changing the number of second subtracted at the end. <? $in_dst="false";
2
7207
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 correct times for everything. i use date.getTimezoneOffset() which works fine and shows the daylight savings time correct value of -4 since im in...
10
5246
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 public static double GetHoursofYear( DateTime aTime ) { DateTime StartYear = new DateTime( aTime.Year, 1, 1 ); return ( aTime.ToOADate() -...
1
1369
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 windows 95/98/me/xp/2000/2003/etc. to handle new daylight savings time rules? are there any patches for .net? win32? etc.? what all else is impacted...
6
1413
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 binaries, etc. that microsoft maintains which have coded in them logic around datetime. e.g. the C# and c++ datetime objects that microsoft...
6
4005
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 calculation on this machine? Ideal option: RPM patch. Worst option: upgrade OS (it's a very old machine).
3
5998
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 with the date functions like DateDiff() or Now() that is used in these classic .asp pages that our webserver hosts? Thanks in advance. J
3
4315
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 Standard Ed. Box for our Domain controller. -We are having issues STILL today in April with the Microsoft Windows Daylight Savings Issues ...
37
4652
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 leap second? By "Unix time" I mean the integer returned by time() and similar functions. I'm concerned about the "down" case. Some of the...
0
1513
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 for the files on my Desktop hard drive I then need to delete my files off my external portable HD and then recopy the "updated time stamp files"...
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.