用字符串表示的日期时间不日历System.Globalization.GregorianCalendar支持 [英] The DateTime represented by the string is not supported in calendar 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屋!