Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

DateTime ticks inconsistent between .NET MF 4.2 and full .NET 4.0?


  • Please log in to reply
3 replies to this topic

#1 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 06 September 2011 - 12:52 AM

Executed the following on my Netduino Plus (running the 4.2 RC1 firmware): Debug.Print(new DateTime(129597249849261120).ToString()); That printed: 09/05/2011 19:36:24 Looks good, basically what I expected. Now over in my full .NET 4.0 app (which is receiving that integer value from the Netduino): string str = new DateTime(129597249849261120).ToString(); That yields: 9/5/0411 7:36:24 PM They are exactly 1600 years apart?

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 06 September 2011 - 02:56 AM

Hi Cabadam, I believe that the datetime "starting time" is different between .NET and .NET Micro Framework. If this is a potential compatibility issue for your project, I'd recommend posting a note over at netmf.codeplex.com. We never share DateTime values betwen devices/computers as integers...but I can see where this would be useful. Chris

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 06 September 2011 - 06:25 AM

Chris is right, indeed. The origin of DateTime in .NET Micro Framework is 1/1/1601, the documentation is incorrect and should be fixed in the upcoming 4.2 version (CodePlex issue #1003). The reason quoted from the source code:

/// NOTES: Why origin is at 1/1/1601.
/// Current civil calendar is named as Gregorian calendar after Pope Gregory XIII as he made adjustments
/// in 1582 (read more at wiki http://en.wikipedia....gorian_calendar). Rules governing
/// leap years were changed from then. Also in that year month October was 21 days instead of usual 31.
/// This poses a problem on calculating date/time difference, leap years etc before 1582 using simple math.
/// For example 1500 was a leap year using old method while it is not using new. But in reality, as part of the
/// history it was leap year. Default CLR origin 1/1/01 gives wrong date time from years before 1582. For example
/// dates like 10/6/1582 does exist in history (see wiki), while CLR managed date/time will not throw an exception
/// if you are to create that date. To stay safe side 1/1/1601 is taken as origin, as was done for Windows.

Also, the initial system time (in absense of any time sync, or built in clock) is 1/1/2009:00:00:00.000 (128752416000000000 ticks).

#4 Cabadam

Cabadam

    Advanced Member

  • Members
  • PipPipPip
  • 90 posts

Posted 06 September 2011 - 12:39 PM

Ah, thanks to both. Since it is intentional, I'll just code in a +1600 years on the .NET 4.0 side of things to account for it (and guess I also need to remember to subtract when sending the opposite way). And thanks for pointing out the existing issue regarding the documentation - I won't open up another issue then.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.