String was not recognized as a valid DateTime “ format dd/MM/yyyy”

前端 未结 13 1423
一整个雨季
一整个雨季 2020-11-22 05:30

I am trying to convert my string formatted value to date type with format dd/MM/yyyy.

this.Text=\"22/11/2009\";

DateTime date = DateTime.Parse(         


        
13条回答
  •  执笔经年
    2020-11-22 06:06

    You can use also

    this.Text = "22112009";
    DateTime newDateTime = new DateTime(Convert.ToInt32(this.Text.Substring(4, 4)), // Year
                                        Convert.ToInt32(this.Text.Substring(2,2)), // Month
                                        Convert.ToInt32(this.Text.Substring(0,2)));// Day
    

提交回复
热议问题