Example

using System;
using System.Globalization;
namespace Samples
{
  public class DateTimeFormatInfoSample
  {
    public static void Main()
    {
      DateTime d = DateTime.Now;
      DateTimeFormatInfo i =
          new CultureInfo("fr-FR").DateTimeFormat;
      string[] f = i.GetAllDateTimePatterns();
      foreach(string s in f)
        Console.WriteLine("ToString(\"{0}\") yields: {1}",
                          s, d.ToString(s, i));
      i = new CultureInfo("en-AU").DateTimeFormat;
      f = i.GetAllDateTimePatterns();
      foreach(string s in f)
        Console.WriteLine("ToString(\"{0}\") yields: {1}",
                          s, d.ToString(s, i));
    }
  }
}
The output is
 ToString("dd/MM/yyyy") yields: 10/06/2003 ToString("dd/MM/yy") yields: 10/06/03 ToString("dd.MM.yy") yields: 10.06.03 ToString("dd-MM-yy") yields: 10-06-03 ToString("yyyy-MM-dd") yields: 2003-06-10 ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.