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.
Jürgen bayer
source share