4

Consider the following simple piece of code:

TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1));
UInt64 microTimestamp = (Convert.ToUInt64(ts.TotalSeconds))*1000000;

Console.WriteLine ("Now: " + DateTime.UtcNow.ToString());
Console.WriteLine ("Microtimestamp: " + microTimestamp);

I have compiled it to an exe and execute it on two machines:

Device 1: MacBook

Now: 12.12.2013 16:26:57
Microtimestamp: 1386865617000000

Device 2: Raspberry Pi

Now: 735214/00/0001 16:25:14
Microtimestamp: 0

Both devices have their date and time correctly set up (which I checked in the OS's control panels). Why the heck does the Raspberry not produce a correct result?

Jesse C. Slicer
  • 19,901
  • 3
  • 68
  • 87
Boris
  • 8,551
  • 25
  • 67
  • 120
  • 1
    What's the current culture on the Raspberry Pi? That would affect the formatting. What does `DateTime.UtcNow.Ticks` give in each case? – Jon Skeet Dec 12 '13 at 16:35
  • Not sure off hand but it might boil down to hardware support to do with time, not sure if the RTC element has anything to do with any of this... – Adam Houldsworth Dec 12 '13 at 16:35
  • Possibly related: http://stackoverflow.com/questions/11805729/datetime-tostring-in-mono-return-invalid-date-00-734718-0001-014138 – Mike Zboray Dec 12 '13 at 16:43
  • Ticks look fine. On my MacBook: 635224634070438680, on the Pi: 635224634158614890 – Boris Dec 12 '13 at 16:45
  • If `DateTime.UtcNow.Ticks` is correct, but `DateTime.UtcNow.ToString()` is not, then it seems the latter is broken on Mono on the Pi – RobSiklos Dec 12 '13 at 16:48

1 Answers1

5

My psychic debugging powers tell me that you are using "hard float" Raspbian (as opposed to "soft float". Rasphian distributes the "hard float" build by default (as its faster), however there is currently a bug in Mono on "hard float" distros caused by issues with the calling conventions for floating point numbers.

Your options are either:

  • Use a "soft float" distro (i.e. wipe your SD card and install a "soft float" version of Raspbian)
  • Patch Mono

See also

Community
  • 1
  • 1
Justin
  • 84,773
  • 49
  • 224
  • 367
  • This has been around for a long time, I'm surprised no one has patched it yet. There should be an open ticket for this somewhere. – Adam Houldsworth Dec 12 '13 at 16:52
  • @AdamHouldsworth There is [one here](https://bugzilla.xamarin.com/show_bug.cgi?id=7938) but its still marked as "NEW" - apparently a fix is coming, its just taking its sweet time – Justin Dec 12 '13 at 16:56
  • Is there an easy way to perform this patch? All I can find is a link to the Git-Repo, no instructions how to get that running on my Pi. Also I'm a Linux noob :-) – Boris Dec 12 '13 at 17:18
  • @Boris I am a bit as well to be honest! I'd probably say that wiping the SD card is easier – Justin Dec 12 '13 at 17:20
  • @Boris Try [here](http://www.raspberrypi.org/phpBB3/viewtopic.php?t=54690&p=416532) – Justin Dec 12 '13 at 22:20
  • Is there a reason why they haven't updated this in months and banned it from their downloads page? Also the Pi won't boot using this image :-( – Boris Dec 13 '13 at 05:18
  • @Boris I think its just an old release (they don't seem to be releasing new soft-float images any more) as for not booting see [Soft-float version of Raspbian does not boot](http://stackoverflow.com/questions/15313521/soft-float-version-of-raspbian-does-not-boot), I remember from when I did this you just need a newer version of the `start.elf` file (and possibly other boot files) – Justin Dec 13 '13 at 08:34
  • 1
    @Boris There is another site for RPi questions: http://raspberrypi.stackexchange.com/ you might get more targeted help there. – Adam Houldsworth Dec 13 '13 at 11:59