Mono中的DateTime.ToString返回无效日期(“00/734718/0001 01:41:38”) [英] DateTime.ToString in Mono return invalid date ("00/734718/0001 01:41:38")

查看:144
本文介绍了Mono中的DateTime.ToString返回无效日期(“00/734718/0001 01:41:38”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过raspbian发行版(Debian GNU / Linux wheezy / sid)将mono(Debian 2.10.8.1-5)正确运行在我的raspberry pi上。我已经安装了单声道与apt-get安装单声道。



但是,我遇到一个有趣的问题,我无法想像。 DateTime.ToString()方法返回无效的字符串。



下面您可以使用控制台输出找到我的示例程序:

 使用系统; 

命名空间MonoTest
{
类程序
{
static void Main(string [] args)
{
DateTime now = DateTime.Now;
Console.WriteLine(Year:+ now.Year);
Console.WriteLine(Month:+ now.Month);
Console.WriteLine(Day:+ now.Day);
Console.WriteLine(DayOfWeek:+ now.DayOfWeek);
Console.WriteLine(DateTime.Now:+ DateTime.Now);
Console.WriteLine(DateTime.Now.ToString(yyyy-MM-dd));
}
}
}

输出:

  pi @ raspberrypi〜/ bin $ mono MonoTest.exe 
年份:2012
月份:8
日:3
DayOfWeek:Friday
DateTime.Now:00/734718/0001 01:41:38
0001-00-734718


有没有人有一个想法这里是什么问题,以及如何说服DateTime.ToString ()返回正确的值?



更新(8/4/2012):跟踪问题回到System.Math.Floor。显然,它总是返回0.我将测试程序改为简单:

  static void Main(string [] args)
{
Console.WriteLine(Floor(1.5):+ System.Math.Floor(1.5));
}

在Windows上,结果是Floor(1.5):1而在我的树莓pi上的单声道设置为Floor(1.5):0。我看到System.Math.Floor被实现为

  [MethodImplAttribute(MethodImplOptions.InternalCall)] 
public extern静态双层(双d);

明天,我会进一步研究这个问题。有人知道为什么这个问题可以存在吗?

解决方案

这是Mono bug #7938 ,它不仅影响DateTime.ToString,而且直接或间接地将浮点数传递给库调用时,在ARM上运行的Linux发行版为硬浮动ABI构建。有关详细信息,请参阅 C#on Raspberry Pi 维基页面。目前没有很好的解决方案,缺少运行软浮动发行版。我仍然希望我们可以很快得到固定的单声道运行时间。


I am trying to get mono (Debian 2.10.8.1-5) to run properly on my raspberry pi with the raspbian distro ("Debian GNU/Linux wheezy/sid"). I have installed mono with apt-get install mono-complete.

However, I am running into an interesting issue that I cannot figure out. The DateTime.ToString() method returns an invalid string.

Below you can find my sample program with the console output:

using System;

namespace MonoTest
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime now = DateTime.Now;
            Console.WriteLine("Year: " + now.Year);
            Console.WriteLine("Month: " + now.Month);
            Console.WriteLine("Day: " + now.Day);
            Console.WriteLine("DayOfWeek: " + now.DayOfWeek);
            Console.WriteLine("DateTime.Now: " + DateTime.Now);
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd"));
        }
    }
}

Output:

pi@raspberrypi ~/bin $ mono MonoTest.exe
Year: 2012
Month: 8
Day: 3
DayOfWeek: Friday
DateTime.Now: 00/734718/0001 01:41:38
0001-00-734718

Interestingly enough, 734718 seems to be the the number of days elapsed till today since 01/01/0001. I have tryed it with a fresh installation on a second board but with the same issue.

Does anyone have an idea what the problem here is and how to convince DateTime.ToString() to return the right value?

Update (8/4/2012): After long digging through the mono source code I was able to trace the issue back to System.Math.Floor. Apparently, it always returns 0. I changed my test program to a simple:

static void Main(string[] args)
{
    Console.WriteLine("Floor(1.5): " + System.Math.Floor(1.5));
}

On Windows the result is "Floor(1.5): 1" Whereas on my mono setup on the raspberry pi is "Floor(1.5): 0". I have seen that System.Math.Floor is implemented as

[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static double Floor (double d);

Tomorrow, I will look further into this issue. Does anyone know why this issue could exist?

解决方案

This is Mono bug #7938, and it affects not just DateTime.ToString, but ANY function that, directly or indirectly, passes a floating-point number to a library call, when running on ARM with a Linux distro built for the hard-float ABI. More details are available at the C# on Raspberry Pi wiki page. There is currently no good fix for this, short of running a soft-float distro. I'm still hoping we can get a fixed mono runtime soon.

这篇关于Mono中的DateTime.ToString返回无效日期(“00/734718/0001 01:41:38”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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