Are .Net's DateTime methods capable of recognising a Leap Second?

孤者浪人 提交于 2019-11-30 07:50:20

问题


With a Leap Second on the horizon for June this year it got me wondering whether the .Net framework is leap second aware? The extra second is to be inserted after the last second of June 30th so UTC will officially be:

2012 June 30,     23h 59m 59s
2012 June 30,     23h 59m 60s
2012 July  1,      0h  0m  0s

Is the .Net framework capable of handling this? Does it even matter if Windows is not Leap Second aware? Will this affect apps in mono running on O/S's that are Leap Second aware?

EDIT:

To expand on this a little bit i'm envisioning a scenario where a Java based solution on Linux (which is Leap Second aware) calls a .Net Web Service passing in something that is a valid timestamp in Java but is out of bounds for .Net. Are there any frameworks that cater for it (Like Noda Time perhaps)?


回答1:


No -

A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond.

The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001, which represents DateTime.MinValue. It does not include the number of ticks that are attributable to leap seconds.

Source: http://msdn.microsoft.com/en-us/library/system.datetime.ticks.aspx




回答2:


The .Net DateTime has no provisions for Leap Seconds, but will simply rely on the OS time. Windows is blissfully unaware of Leap Seconds(1)(2), and so will just have the notion of time as it receives it from its NTP master (I believe the default for a non-domain connected machine is time.windows.com), which is probably serving up UTC including leap seconds.

See also my answer to "Calculating Future Epoch Time in C#" which goes into more details.

  1. http://support.microsoft.com/kb/909614
  2. http://www.meinberg.de/english/info/leap-second.htm


来源:https://stackoverflow.com/questions/8760674/are-nets-datetime-methods-capable-of-recognising-a-leap-second

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!