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

前端 未结 13 1497
一整个雨季
一整个雨季 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 05:54

    You might need to specify the culture for that specific date format as in:

        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); //dd/MM/yyyy
    
        this.Text="22/11/2009";
    
        DateTime date = DateTime.Parse(this.Text);
    

    For more details go here:

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

提交回复
热议问题