質問

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