.Net (3.5) Formats Times Using Dots Instead of Colons as Timeseparator for It-It Culture

.NET (3.5) formats times using dots instead of colons as TimeSeparator for it-IT culture?

This seems to be a .NET 3.5 issue. In .NET 4.0 the code you posted uses a colon as expected. Seems like a strange breaking change between the framework versions, but seems like upgrading to .NET 4 will solve the problem.

Why does DateTime.ToString() seem to ignore the thread current culture?

The time separator for "it-IT" culture is a colon, as you can see if you check ci.DateTimeFormat.TimeSeparator. I guess that the MSDN documentation is wrong.

You can always manually change the time separator (ci.DateTimeFormat.TimeSeparator = ".") if you really need it.

EDIT: As stated in comments, it seems that the time separator for the it-IT culture was a dot in .NET 3.5, but was changed to a colon in .NET 4.0.

Formatting time in Android using norwegian locale returns dot and not colon as seperator

Answer from Google engineer:
http://code.google.com/p/android/issues/detail?id=42104

"As usual, my advice is not to use android.text.format.DateFormat. if you use java.text.DateFormat it'll use formats from the CLDR.

the problem with that is that it won't respect the user's 12/24-hour preference. i'm working on trying to get that information down to libcore so we can just do the right thing. (and then we can switch the duplicated API in frameworks/base over to using the libcore implementation.)"

DateTime timestamp has period instead of colon

As you says, this is about customer's culture. Specifically CultureInfo.DateTimeFormat.

This property returns a DateTimeFormatInfo object that defines the culturally appropriate format of displaying dates and times.

This object have a property TimeSeparator that gets or sets the string that separates the components of time, that is, the hour, minutes, and seconds.

You can setup this property to specify a separator like :.

However a better approach is passing a specific culture to ToString() method like CultureInfo.InvariantCulture (culture-independent):

string dateFrom = ((DateTime)row["date_from"]).ToString(CultureInfo.InvariantCulture);
string dateTo = ((DateTime)row["date_to"]).ToString(CultureInfo.InvariantCulture);

or use your own format:

string dateFrom = ((DateTime)row["date_from"]).ToString("yyyy-MM-dd HH:mm:ss");
string dateTo = ((DateTime)row["date_to"]).ToString("yyyy-MM-dd HH:mm:ss");

How to format DateTime to local users locale in short time format using MonoTouch

Try this:

var formatter = new NSDateFormatter ();
formatter.TimeStyle = NSDateFormatterStyle.Short;
Console.WriteLine (formatter.ToString (DateTime.Now));

That said, the bug with dot/colon as the time separator for Norwegian locales has been fixed in Mono 2.12, so when MonoTouch switches to use Mono 2.12 instead of Mono 2.10 (hopefully early next year) you will be able to use this managed alternative too:

Console.WriteLine (DateTime.Now.ToString (new CultureInfo ("nb-NO").DateTimeFormat.ShortTimePattern));


Related Topics



Leave a reply



Submit