Mac 上的 Silverlight 日期时间格式化问题

发布于 2024-10-25 10:02:13 字数 436 浏览 1 评论 0原文

这里有一个有趣的问题。如果当前日期是 2011 年 3 月 23 日,并且我在 Mac 上的 silverlight 应用程序中运行以下代码...

MessageBox.Show(DateTime.Now.ToString("yyyy-MM-dd, ddd dddd");

它返回: “2011-03-23,星期四”,实际上 3 月 21 日是星期三!上面的代码在 Windows PC 上完美运行,

我认为这可能与客户 Mac 上的计算机设置有关,但他们尝试了 3 台其他 Mac 和 ddd。一周的第二天返回(我想是星期四而不是星期三),所以我出去带了一台 Mac Book Pro,

Mac 上的 Silverlight 插件版本 也出现了问题。 60129.0,当前文化是 en-NZ,浏览器是 Safari。

如果有人能告诉我发生了什么或提供修复程序,那就太好了。

Here an interesting problem. If the current date is March 23, 2011 and I run the following code in my silverlight application on a Mac...

MessageBox.Show(DateTime.Now.ToString("yyyy-MM-dd, ddd dddd");

It returns: "2011-03-23, Thu Thursday" when in fact March 21 is a Wednesday! The above code works perfectly on a Windows PC.

I thought this maybe related to the computer settings on the customers Mac but they tried 3 other Macs and ddd return the next day of the week (i.e. Thu instead of Wed). Hmmm I thought, so I went out and brought a Mac Book Pro and the problem happened on that as well.

My Silverlight plug-in version on the mac is 4.0.60129.0, current culture is en-NZ, browser is Safari.

If anyone can tell me whats going on or provide a fix that would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲性难收 2024-11-01 10:02:13

作为解决方法,我将以下代码添加到我的 App.xaml.cs 构造函数中

if (new DateTime(2011, 3, 28).ToString("ddd") == "Tue")
{
    CultureInfo culture = new CultureInfo("en-AU");

    culture.DateTimeFormat.DayNames = new[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
    culture.DateTimeFormat.AbbreviatedDayNames = new[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
    culture.DateTimeFormat.ShortestDayNames = new[] { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };

    System.Threading.Thread.CurrentThread.CurrentCulture = culture;
    System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
}

For a workaround I added the following code to my App.xaml.cs constructor

if (new DateTime(2011, 3, 28).ToString("ddd") == "Tue")
{
    CultureInfo culture = new CultureInfo("en-AU");

    culture.DateTimeFormat.DayNames = new[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
    culture.DateTimeFormat.AbbreviatedDayNames = new[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
    culture.DateTimeFormat.ShortestDayNames = new[] { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };

    System.Threading.Thread.CurrentThread.CurrentCulture = culture;
    System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文