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

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

问题描述

我正在尝试使用 raspbian 发行版(Debian GNU/Linux wheezy/sid")让单声道(Debian 2.10.8.1-5)在我的树莓派上正常运行.我已经用 apt-get install mono-complete 安装了 mono.

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.

但是,我遇到了一个我无法弄清楚的有趣问题.DateTime.ToString() 方法返回无效字符串.

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"));
        }
    }
}

输出:

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

有趣的是,734718 似乎是从 01/01/0001 到今天经过的天数.我已经在第二块板上重新安装了它,但遇到了同样的问题.

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.

有谁知道这里的问题是什么以及如何说服 DateTime.ToString() 返回正确的值?

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

更新(2012 年 8 月 4 日):经过长时间挖掘 Mono 源代码后,我能够将问题追溯到 System.Math.Floor.显然,它总是返回 0.我把我的测试程序改成了一个简单的:

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));
}

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

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,它不仅会影响 DateTime.ToString,还会影响任何直接或间接将浮点数传递给库调用的函数,当在 ARM 上使用为硬浮点构建的 Linux 发行版运行时ABI.在Raspberry Pi 上的C# wiki 页面上提供了更多详细信息.除了运行软浮动发行版之外,目前还没有好的解决方法.我仍然希望我们能尽快获得固定的单声道运行时.

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天全站免登陆