What does IFormatProvider do?

后端 未结 8 2194
一向
一向 2021-01-30 12:27

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

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

相关标签:
8条回答
  • 2021-01-30 12:56

    By MSDN

    The .NET Framework includes the following three predefined IFormatProvider implementations to provide culture-specific information that is used in formatting or parsing numeric and date and time values:

    1. The NumberFormatInfo class, which provides information that is used to format numbers, such as the currency, thousands separator, and decimal separator symbols for a particular culture. For information about the predefined format strings recognized by a NumberFormatInfo object and used in numeric formatting operations, see Standard Numeric Format Strings and Custom Numeric Format Strings.
    2. The DateTimeFormatInfo class, which provides information that is used to format dates and times, such as the date and time separator symbols for a particular culture or the order and format of a date's year, month, and day components. For information about the predefined format strings recognized by a DateTimeFormatInfo object and used in numeric formatting operations, see Standard Date and Time Format Strings and Custom Date and Time Format Strings.
    3. The CultureInfo class, which represents a particular culture. Its GetFormat method returns a culture-specific NumberFormatInfo or DateTimeFormatInfo object, depending on whether the CultureInfo object is used in a formatting or parsing operation that involves numbers or dates and times.

    The .NET Framework also supports custom formatting. This typically involves the creation of a formatting class that implements both IFormatProvider and ICustomFormatter. An instance of this class is then passed as a parameter to a method that performs a custom formatting operation, such as String.Format(IFormatProvider, String, Object[]).

    0 讨论(0)
  • 2021-01-30 13:03

    The DateTimeFormatInfo class implements this interface, so it allows you to control the formatting of your DateTime strings.

    0 讨论(0)
提交回复
热议问题