夏令时活动

编程入门 行业动态 更新时间:2024-10-26 14:27:05
本文介绍了夏令时活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

夏时制发生时,我需要做一些事情.我知道有一些 发生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类. msdn.microsoft/en-us/library/system.timezone.aspx [^ ]该类具有一个非常酷的功能,称为"IsDaylightSavingTime(DateTime)".您可以利用该功能和当前日期来查看是否在DST中. 如果将以前的DST检查存储在某个地方,则可以将旧DST检查与当前DST检查进行比较,并检测何时进行更改.由于它是框架的一部分,因此如果该位置的DST参数发生更改,则应该对其进行更新(偶尔会这样做). 霍根 kh_yaniv293, Try using the System.Timezone class. msdn.microsoft/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

更多推荐

夏令时活动

本文发布于:2023-10-28 08:19:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536072.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:夏令时

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!