我似乎无法找到如何将字符串转换为日期时间.这是我约会的样子:"23-nov-12".
我尝试了以下方法:
DateTime convertedDate = DateTime.ParseExact("dd-MMM-yy", "23-nov-12", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
并且
DateTime convertedDate = DateTime.ParseExact("0:d-MMM-yy", "23-nov-12", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)
但我总是得到以下错误:
字符串未被识别为有效的DateTime.
你的论点是错误的.日期是第一位的.
DateTime convertedDate = DateTime.ParseExact("23-nov-12", "dd-MMM-yy", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)