.NET 4.5 DateTime format / convert error with upper sorb culture

Using the culture of the upper sorb (hsb) DateTime object converted to a string uses the format "d. M. yyyy H.mm.ss' hodź.". For example, ToString ("G") returns "12.31.2011 06/05/07 hodź". December 31, 2011 05:06:07.

The problem is that trying to convert such a string back to DateTime does not lead to true. Even simpler lines, such as "1. 1. 2011" or "1.1.2011", do not lead to success. And just in case, someone offers to transfer the culture during conversion / transfer: I did it, of course.

Trying to parse "1.2.3" leads to the current date with a time of 01:02:03.

I believe that a mistake. Or does someone know what might be wrong?

I am using RTF.NET 4.5 on a Windows 8 RTM machine.

Example:

DateTime date = DateTime.Now; CultureInfo culture = new CultureInfo("hsb"); string dateString = date.ToString("G", culture); DateTime convertedDate; bool dateOkay = DateTime.TryParse(dateString, culture, DateTimeStyles.AllowInnerWhite, out convertedDate); Console.WriteLine(dateOkay); // This results false although the date string was read by // ToString("G") (ie '20. 9. 2012 12.28.10 hodź.') and should be okay dateString = "1. 1. 2000"; dateOkay = DateTime.TryParse(dateString, culture, DateTimeStyles.AllowInnerWhite, out convertedDate); Console.WriteLine(dateOkay); // This results in false although the date string should be okay dateString = "1.1.2000"; dateOkay = DateTime.TryParse(dateString, culture, DateTimeStyles.AllowInnerWhite, out convertedDate); Console.WriteLine(dateOkay); // This results also in false dateString = "1.2.3"; dateOkay = DateTime.TryParse(dateString, culture, DateTimeStyles.AllowInnerWhite, out convertedDate); Console.WriteLine(dateOkay + ": " + convertedDate); // This results strangely in true. The converted date is the current date // with time 01:02:03. 
+7
source share
1 answer

In .Net 4.5, "hsb" is marked as a neutral culture, so all DateTime syntax will be executed by the standard format provider. Use DateTime.ParseExact with a format string instead. http://www.codeproject.com/Articles/3612/Use-of-different-Date-Time-formats-and-Culture-typ

=================================

I found that the “IsNeutralCulture” flag in CultureInfo is “true,” the date string syntax in invariant formats (en-US). When I transferred the format MM / dd / yyyy DateTime.TryParse correctly handled the date for the "hsb" culture.

And some quotes from the article I presented: "DateTimeFormatInfo can only be created for an invariant culture or for a specific culture, and not for a neutral culture. DateTimeFormatInfo inherits from Object and implements the ICloneable and IFormarProvider interfaces."

I found that DateTimeFormatInfo is specified for the "hsb" culture, but, as I said earlier, IsNeutralCulture = true. I expect that in the .Net framework 4.5, DateTimeFormatInfo is not used to parse dates when "IsNeutralCulture" is "true"

0
source

All Articles