VicoMan
VicoMan

Reputation: 289

Odd results with parsing a 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"

it throws an exception

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

Anyone can tell me what I'm doing wrong?

Upvotes: 4

Views: 71

Answers (1)

John Woo
John Woo

Reputation: 263683

use HH instead of hh

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

HH is for 24-hr
hh is for 12-hr

Upvotes: 7

Related Questions