DateTime.ParseExact string format exception

后端 未结 3 1501
执念已碎
执念已碎 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 07:05

    Using the following date format expression will allow you to use either single or double digit day and month elements.

    "M/d/yyyy"
    

    Note that the capital M is significant - a lower case m is the placeholder for minutes.

    You will find more information related to date format strings here.

    You can use the following Powershell command to test them.

    [DateTime]::ParseExact('01/01/2010', 'M/d/yyyy', $null)
    

提交回复
热议问题