C# DateTime ToString Standard culture format

Can I alter the standard output format of a DateTime for a specific culture. Example:

class Program
{
    static void Main(string[] args)
    {
        PrintCultureDateTime("ca-ES");
        PrintCultureDateTime("es-ES");
        PrintCultureDateTime("en-US");
        PrintCultureDateTime("en-GB");
        PrintCultureDateTime("pt-PT");
    }

    public static void PrintCultureDateTime(string culture)
    {
        string result = new DateTime(2017, 10, 1).ToString("d", 
            CultureInfo.GetCultureInfo(culture));
        Console.WriteLine(string.Format("{0}: {1}", culture, result));
    }
}

Output:

ca-ES: 1/10/2017
es-ES: 01/10/2017
en-US: 10/1/2017
en-GB: 01/10/2017
pt-PT: 01/10/2017

What I want is to use two digits for day and month using standard "d" format or another standartd one, in order to fix the size of DateTime strings . Something like that output:

ca-ES: 01/10/2017
es-ES: 01/10/2017
en-US: 10/01/2017
en-GB: 01/10/2017
pt-PT: 01/10/2017
Jon Skeet
people
quotationmark

You can use DateTimeFormatInfo.ShortDatePattern to get the pattern, and then replace d with dd if you really want to. You might need to consider corner cases such as escaped or quoted d patterns though - as well as obviously not replacing dd with dddd. (Note that the format info from a system culture will be read-only; clone the culture to get one with a read/write format info.) You'd then do the same for months as well, of course. You may even need to change the years part.

It's not clear to me that it's a good idea to do this though - by the time you've changed the format, it's not really "the standard short date format for the culture" any more.

Even after all of this, there's no guarantee that it'll be the same length for all cultures. There's nothing to stop a culture from using a short date format of "'Year:' yyyy '; Month: ' MM '; 'Day: 'dd". It would be highly unusual, but not invalid.

people

See more on this question at Stackoverflow