문제

my code for converting date is given below,

        DateTime dat1 = Convert.ToDateTime(txtDOB.Text);
        string date2 = dat1.ToString("MM/dd/yyyy");

i got error like this,

Exception Details: System.FormatException: String was not recognized as a valid DateTime.

Source Error:

Line 68: DateTime dat1 = Convert.ToDateTime(txtDOB.Text);

how can recover this,plzzzz help...

도움이 되었습니까?

해결책

I guess you should Use DateTime.ParseExact with the format "MM/dd/yyyy"

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

you can go though the below link for more information

http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top