该字符串未被识别为有效的datetime

来源:百度知道 编辑:UC知道 时间:2024/06/11 01:19:12
有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。

************** 异常文本 **************
System.FormatException: 该字符串未被识别为有效的 DateTime。有一个从索引 9 处开始的未知字。
在 System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
在 System.Windows.Forms.RadioButton.PerformAutoUpdates(Boolean tabbedInto)
在 System.Windows.Forms.RadioButton.set_Checked(Boolean value)
在 System.Windows.Forms.RadioButton.OnClick(EventArgs e)
在 System.Windows.Forms.RadioButton.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 ms

上面的提示不是说的很清楚了么?--->> 该字符串未被识别为有效的 DateTime。有一个从索引 9 处开始的未知字。

字符串转换为DateTime方法有很多。
DateTime.Parse("2009-1-1 11:11:11")
多数出现转换错误的情况,出错最多的是
1、中文的杠号与英文的杠号。
2、日期与时间之间只有一个空格,多则出错。