[英]Parameter incorrect issue with DateTime.ParseExtract
I have the following line. 我有以下几行。
DateTime.ParseExact("08-11-2013 07:38:05", "yyyy-MM-dd HH:mm:ss", Nothing)
It throws an error. 它抛出一个错误。
Parameter is incorrect. 参数不正确。
StackTrace 堆栈跟踪
at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style) at System.DateTime.ParseExact(String s, String format, IFormatProvider provider)
System.DateTime.ParseExact(String s,String format,IFormatProvider provider)的System.DateTimeParse.ParseExact(String s,String format,DateTimeFormatInfo dtfi,DateTimeStyles样式)
Thanks in advance. 提前致谢。
Your format doesn't match that date you are providing, It should be: 您的格式与您提供的日期不符,应该是:
"dd-MM-yyyy HH:mm:ss"
Considering you meanr November 8, 2013 考虑到你的意思是2013年11月8日
You code should be: 你的代码应该是:
DateTime dt = DateTime.ParseExact("08-11-2013 07:38:05",
"dd-MM-yyyy HH:mm:ss",
CultureInfo.InvariantCulture); // Instead of Nothing
You can also use "dM-yyyy HH:mm:ss"
format, since it will consider both single digit/double digit day and month. 您还可以使用
"dM-yyyy HH:mm:ss"
格式,因为它将考虑单日/双位数日和月。
Also it appears that you are coming from VB.Net back ground, where Nothing
is default value, in C# you can use null
for your case or better to use CultureInfo.InvariantCulture
此外 ,您似乎来自VB.Net的背景,其中
Nothing
是默认值,在C#中您可以为您的案例使用null
或更好地使用CultureInfo.InvariantCulture
For more see: Custom Date and Time Format Strings 有关更多信息,请参阅: 自定义日期和时间格式字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.