DateTime.ParseExact string format exception

后端 未结 3 1500
执念已碎
执念已碎 2020-12-19 06:32

I am trying to convert a string into datetime with the following C# code,

DateTime dTo = DateTime.ParseExact(dateTo, \"mm/dd/yyyy\", CultureInfo.InvariantCul         


        
3条回答
  •  再見小時候
    2020-12-19 06:59

    You could try this format: MM/dd/yyyy, but I think there's no single format string that could support both inputs. You could test if the length of your dateTo string is less than 10 characters use M/d/yyyy, otherwise MM/dd/yyyy.

提交回复
热议问题