更新时间:2023-02-03 08:03:10
试试这个:
DateTime.ParseExact(str, "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
如果字符串的格式可能不正确(并且您希望避免出现异常),您可以像这样使用 DateTime.TryParseExact
方法:
If the string may not be in the correct format (and you wish to avoid an exception) you can use the DateTime.TryParseExact
method like this:
DateTime dateTime;
DateTime.TryParseExact(str, "yyyyMMddHHmmss",
CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime);