Alex Rivera | Logout

What does IFormatProvider do?

Asked 2009-02-03T10:46:37.403
114

I was playing around with the Datetime.ParseExact method, and it wants an IFormatProvider...

It works giving null as input, but what exactly does it do?

Edit
Report

1 Answer

23

Passing null as the IFormatProvider is not the correct way to do this. If the user has a custom date/time format on their PC you'll have issues in parsing and converting to string. I've just fixed a bug where somebody had passed null as the IFormatProvider when converting to string.

Instead you should be using CultureInfo.InvariantCulture

Wrong:

string output = theDate.ToString("dd/MM/yy HH:mm:ss.fff", null);

Correct:

string output = theDate.ToString("dd/MM/yy HH:mm:ss.fff", CultureInfo.InvariantCulture);
answered 2013-01-07T11:26:42.860

Your Answer