string not recognized as valid datetime with same format

前端 未结 2 722
温柔的废话
温柔的废话 2021-01-24 23:13

I have this string: 02/01/2019 13:00:00 I want get only the 02/01/2019, so I did:

var date = DateTime.ParseExact(match.datetime.ToString(), \"dd/MM/         


        
2条回答
  •  暖寄归人
    2021-01-24 23:41

    24 hour time is represented by HH for parsing, not hh.

    Try something like this:

    DateTime.ParseExact("02/01/2019 13:00:00", "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture)
    

提交回复
热议问题