System.ArgumentOutOfRangeException: 年、月和日参数描述无法表示的 DateTime。

来源:互联网 发布:linux uboot 启动详解 编辑:程序博客网 时间:2024/06/06 19:30

在实用系统控件DateTimePicker,将CustomeFormat 设置成(yyyy年MM月),并且将Foramt 设置成custom,有时会出现奇怪的现象:特殊日期会出现错误。

 

错误详细信息:

System.ArgumentOutOfRangeException: 年、月和日参数描述无法表示的 DateTime。
  在 System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
  在 System.Windows.Forms.DateTimePicker.SysTimeToDateTime(SYSTEMTIME s)
  在 System.Windows.Forms.DateTimePicker.WmDateTimeChange(Message& m)
  在 System.Windows.Forms.DateTimePicker.WmReflectCommand(Message& m)
  在 System.Windows.Forms.DateTimePicker.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 msg, IntPtr wparam, IntPtr lparam)

 

尝试多遍,特殊日期,31号,29号这样的日期,有时会出现错误。如果设置CustomeFormat (yyyy年MM月dd日)就行啦。将控件大小设置成(yyyy年MM月)的大小。这样日就不会出现,你只需后台代码格式下就OK

原创粉丝点击