夏令时活动 [英] Daylight Saving event

查看:87
本文介绍了夏令时活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


夏时制发生时,我需要做一些事情.我知道有一些
发生TimeChange事件,但是当用户手动更改时间并且我无法区分这两种情况时,也会发生此事件.
我需要一个可以肯定地告诉我的事件:现在发生了夏时制,而不是手动更改时间".

请指教,
谢谢.

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.

推荐答案

kh_yaniv293,

尝试使用System.Timezone类. http://msdn.microsoft.com/en-us/library/system.timezone.aspx [^ ]该类具有一个非常酷的功能,称为"IsDaylightSavingTime(DateTime)".您可以利用该功能和当前日期来查看是否在DST中.

如果将以前的DST检查存储在某个地方,则可以将旧DST检查与当前DST检查进行比较,并检测何时进行更改.由于它是框架的一部分,因此如果该位置的DST参数发生更改,则应该对其进行更新(偶尔会这样做).

霍根
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





也许这不是您100%的主题,但是也许您可以使用此简单的证据来处理某些问题,并在发生更改时创建事件.

Hi,


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

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


不知道您要查找的事件是否存在,但是作为解决方法,您可以使用Windows事件日志.

当用户更改时间时,此事件将被写入Windows事件日志中.因此,在发生TimeChange事件时,您可以阅读Windows事件日志以检测手动时间更改和夏时制.

Piet
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


这篇关于夏令时活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆