Click here to Skip to main content
15,847,077 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi,
I need to do something when daylight saving occurs. I know that there is some
TimeChange event that happens but this event is also happens when user change the time manualy and i cant distinguish between those 2 situation.
I need an event that will tell me for sure: "DayLight saving happened now and not manual time change".

Please advice,
Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 5-Mar-12 14:38pm    
Good question, my 5, but preliminary Google search shows that this is problematic.
--SA

Don't know the existence of the event you're looking for, but as a workaround you could use the windows events log.

When a user changes the time this event will be written in the windows events log. So when the TimeChange event occurs you could read the windows events log to detect manual time changes and daylight savings.

Piet
 
Share this answer
 
kh_yaniv293,

Try using the System.Timezone class. http://msdn.microsoft.com/en-us/library/system.timezone.aspx[^] This class has a really cool function called "IsDaylightSavingTime(DateTime)". You could leverage that function with the current date to see if you're in DST or not.

If you store the previous DST check somewhere, you can compare the old with the current and detect when the change takes place. Since its part of the framework, it should be updated if the DST parameters change for that location, which they occasionally do.

Hogan
 
Share this answer
 
Comments
ARBebopKid 5-Mar-12 17:13pm    
my 5
Hi,


perhaps it itsn't 100% your topic, but maybe you can handle something with this simple proof and create a event if changed.

C#
public bool IsDay(DateTime value)
        {
            if (value.Hour > 7 && value.Hour < 19)
                return true;
            else
                return false;
        }
        public bool IsNight(DateTime value)
        {
            bool isDay = IsDay(value);
            return !isDay;
        }


Best Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900