.NET (3.5) formats time using periods, not colons, how is TimeSeparator for it - IT culture?

According to Wikipedia (and confirmed in response to Dario Soler ), in Italy they format the time using colons:

24-hour notation is used in writing with a colon as a separator. Example: 2:05 p.m. Protocols are written in two digits; hour numbers can be written with or without zero.

However, running the following code seems to print the dots:

using System.Globalization;

Thread.CurrentThread.CurrentCulture = new CultureInfo("it-IT");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("it-IT");
// Outputs "11.08"
Console.WriteLine(DateTime.Now.ToShortTimeString());

// Outputs "."
Console.WriteLine(new CultureInfo("it-IT").DateTimeFormat.TimeSeparator);

Is this a structural error? What is the best way to “fix” it? TimeSeparatorconfigurable - we just have to overwrite it before the appointment Thread.CurrentThread.CurrentCulture, etc.

+3
source share
4

, .NET 3.5. .NET 4.0 , , , . , , .NET 4 .

+3

, , 24- . ( , ).

, , . - :

Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");
+6

/ (TimeSeparator) ., :.

, , , .

DateTime : - . , - , , DateTime .

+3

Oded answer, , , , :

var culture = CultureInfo.GetCultureInfo("it-IT");
var stringValue = new TimeSpan(100, 100, 100, 100, 100).ToString(null, culture);
var timespan = TimeSpan.Parse(stringValue, culture);
// Another example
var culture = CultureInfo.GetCultureInfo("it-IT");
var stringValue = DateTime.Now.ToString(null, culture);
var dateTime = DateTime.Parse(stringValue, culture);
0

All Articles