1

In docs for Microsoft C# DateTime.ToString Method (String, IFormatProvider) says:

The provider parameter defines the pattern that corresponds to the standard format specifiers, as well as the symbols and names of date and time components.

I have noticed that docs only mentioned the standard format specifiers that is acting with provider parameter

Could someone explain to me why only standard format specifiers have been mentioned here "acting with provider parameter" instead of standard and Custom format specifiers?

Josh Withee
  • 9,922
  • 3
  • 44
  • 62
Ammar
  • 91
  • 2
  • 13

2 Answers2

0

Because custom formats are supported by a different interface, ICustomFormatter. Most concrete implementations support both.

John Wu
  • 50,556
  • 8
  • 44
  • 80
0

IMHO, I strongly suspect this paragraph is try to explain that those standard format specifiers are defined in the IFormatProvider itself.

For example;

and more..

As you can see, those format specifiers defined by the IFormatProvider itself. Their representing values defined what those properties are defined.

enter image description here

On the other hand, the custom date and time format specifiers are not defined in the IFormatProvider itself.

For example, is there any property in the IFormatProvider that defines fffffff, hh or zzz custom specifiers? No.

I think that's the "main" message on this paragraph.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • ok i get the idea , Since Custom Format Specifiers defined in ICustomFormatter we can not use them in IFormatProvider – Ammar Jul 27 '18 at 16:35
  • 1
    @AmmarBamhdi I wouldn't say that _Since Custom Format Specifiers defined in ICustomFormatter.._ As documented; `ICustomFormatter interface is implemented with the IFormatProvider interface to customize the behavior of two .NET Framework composite string formatting methods that include an IFormatProvider parameter. Specifically, the ICustomFormatter interface can provide custom formatting of the value of an object passed to the String.Format(IFormatProvider, String, Object[]) and StringBuilder.AppendFormat(IFormatProvider, String, Object[]) methods` ++ – Soner Gönül Jul 31 '18 at 09:12
  • 1
    ++ Also from `IFormatProvider` documentation; `The .NET Framework also supports custom formatting. This typically involves the creation of a formatting class that implements` **both** `IFormatProvider and ICustomFormatter.` Also you might wanna check the connections between `IFormattable`, `IFormatProvider` and `ICustomFormatter` on https://stackoverflow.com/q/1697470/447156 as well. – Soner Gönül Jul 31 '18 at 09:12