我遇到了与DateTime.ParseExact
相关的问题。无法解析月份的1位数字符串。
//this works fine with 2 digits for month
DateTime.TryParseExact("030405", "MMddyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
//this works also fine with 1 digit for month but with hyphen or space
DateTime.TryParseExact("3-04-05", "M-dd-yy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
DateTime.TryParseExact("3 04 05", "M dd yy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
//but this DOES NOT work with 1 digit without hyphen
DateTime.TryParseExact("30405", "Mddyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
对我而言看起来不合逻辑。