Вопрос

if I use this line of code on an azure website

DateTime.Now.ToString(new System.Globalization.CultureInfo("it-IT"))

the page prints

13/02/2014 12.08.45

but the time separator is wrong, should be

13/02/2014 12:08:45

Am I doing something wrong or is an azure bug?

EDIT

I run the test program Jon Skeet suggest me, and these are the results

PS D:\desktop> .\test
13/02/2014 12:50:32
Runtime: 2.0.50727.5472
PS D:\desktop> .\test
13/02/2014 12:50:47
Runtime: 4.0.30319.18408
Это было полезно?

Решение 2

Actually it's a Windows 8 (Server 2012) issue. In Windows 8 the it-IT culture was updated to use . instead of : as it used to in Windows 7. In 8.1 it was updated again to : after some feedback from customers.

You can see that in Control Panel if you have a Windows 7 or 8.1 machine vs a Windows 8 machine. Culture data shouldn't be considered stable (except for Invariant)

Azure Websites are currently using Windows 8 (Server 2012) VMs

Windows 7 and 8.1

Windows 7 and 8.1 it-IT culture

Windows 8

enter image description here

for a workaround please check Shawn Steele reply here http://social.msdn.microsoft.com/Forums/en-US/bf5fa2c1-b6ce-4e4e-b9dd-17191afca4be/web-services-culture?forum=windowsazurewebsitespreview&prof=required

Другие советы

I believe it's to do with the version of the CLR being used. On the CLR prior to v4, the culture information being used did have the time separator as .. On CLR v4+, it's :. I don't know why... presumably CLR v4+ is reading the regional information from a different (newer?) location. (I suspect it's down to the CLR version being used, basically.)

Anyway, I suspect if you can force your Azure service to use .NET 4, it will be okay. I suspect you'll find it's using .NET 3.5 at the moment.

As an example, take this code:

using System;
using System.Globalization;

class Test
{
    static void Main()
    {
        CultureInfo culture = new CultureInfo("it-IT");
        Console.WriteLine(DateTime.Now.ToString(culture));
        Console.WriteLine("Runtime: {0}", Environment.Version);
    }
}

Compile it with the C# 2 compiler:

c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc Test.cs

And create a Test.exe.config file:

<configuration>
   <startup>
      <supportedRuntime version="v2.0.50727"/>
      <supportedRuntime version="v4.0"/>
   </startup>
</configuration>

Comment out one of those supportedRuntime elements at a time to see the difference.

No, it is not a bug.

Because it-IT culture's TimeSeperator is . not :

CultureInfo c = CultureInfo.CreateSpecificCulture("it-IT");
Console.WriteLine(c.DateTimeFormat.TimeSeparator); //Prints .

EDIT: Wait a second.. There is something going tricky here..

I think Jon is right because on my machine I run this with .NET 3.5 and that's why it prints . instead of :

If you can force your Azure service to use .NET 4+ you get : instead of .

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top