用字符串表示的日期时间不日历System.Globalization.GregorianCalendar支持 [英] The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar

查看:2823
本文介绍了用字符串表示的日期时间不日历System.Globalization.GregorianCalendar支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想救出生日期到SQL数据库,但每次获得新例外,数据库字段类型是日期时间。这里
是我的代码



  usinfo.BirthDate = DateTime.ParseExact(txtDOB.Text.ToString(),MM / DD / YYYY,CultureInfo.InvariantCulture); 


解决方案

问题:您是解析首先使用 MM / DD / YYYY
,但你给日期第一这样的 31/04/2012



Soluton: 您需要使用 DD / MM / YYYY 格式



试试这个:

  usinfo.BirthDate = DateTime.ParseExact(txtDOB.Text.ToString(),DD / MM / YYYY,
的CultureInfo。 InvariantCulture的);



编辑:您enetered无效日期这里 31/04/2012



四月月不能有 31 days.it最多可有30天。
,所以你需要输入有效日期。


I simply want to save Date of Birth into SQL database, but every time getting new exception, database field type is datetime. here is my code

 usinfo.BirthDate = DateTime.ParseExact(txtDOB.Text.ToString(), "MM/dd/yyyy", CultureInfo.InvariantCulture);

解决方案

Problem : You are parsing the Month first using MM/dd/yyyy, but you are giving date first like this 31/04/2012

Soluton : You need to use dd/MM/yyyy format.

Try This:

usinfo.BirthDate = DateTime.ParseExact(txtDOB.Text.ToString(), "dd/MM/yyyy", 
                                                CultureInfo.InvariantCulture);

EDIT: You enetered an invalid Date here 31/04/2012.

April Month can not have 31 days.it can have maximum 30 Days. so you need to enter the Valid Date.

这篇关于用字符串表示的日期时间不日历System.Globalization.GregorianCalendar支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆