Odd results with parsing Datetime C #

I have the following code:

IFormatProvider culture = new System.Globalization.CultureInfo("es-ES", true); date = DateTime.ParseExact(_date, "yyyy-MM-dd hh:mm", culture); 

for _date = "2012-11-17 15:00"

he throws an exception

but for _date = "2012-11-17 10:00" works

Can anyone tell me what I'm doing wrong?

+4
source share
1 answer

use HH instead of HH

 date = DateTime.ParseExact(_date, "yyyy-MM-dd HH:mm", culture); 

HH - within 24 hours
HH is 12 hours

+7
source

Source: https://habr.com/ru/post/1446668/


All Articles