The ToString and string.Format methods let you use formatting characters to format a DateTime value, but it’s not easy to remember all of the characters you might want to use. To make using standard formats easier, the DateTime class provides several standard formatting methods that return a DateTime value in a particular format. Note that these are locale-aware methods so the result you get depends on the system’s configuration.
This example builds a ListView that demonstrates the various formatting methods. It then uses code from the example Use ListView data to generate HTML TABLE code in C# to convert the results into the following HTML table.
|ToLongDateString||D||Monday, August 18, 2014|
|ToString||G||8/18/2014 5:03:16 PM|