Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does IFormatProvider do?

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

It works inputting null, but what exactly does it do?

like image 402
Moulde Avatar asked Feb 03 '09 10:02

Moulde


People also ask

Which is an object that implements the IFormatProvider interface?

The . NET Framework includes three format providers, all of which implement the IFormatProvider interface: NumberFormatInfo supplies numeric formatting information, such as the characters to use for decimal and group separators, and the spelling and placement of currency symbols in monetary values.

What is ParseExact C#?

ParseExact(String, String, IFormatProvider) Converts the specified string representation of a date and time to its DateTime equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly.


1 Answers

In adition to Ian Boyd's answer:

Also CultureInfo implements this interface and can be used in your case. So you could parse a French date string for example; you could use

var ci = new CultureInfo("fr-FR"); DateTime dt = DateTime.ParseExact(yourDateInputString, yourFormatString, ci); 
like image 120
Andrei Rînea Avatar answered Oct 03 '22 09:10

Andrei Rînea