Docs: Localized date format

Created on 24 Aug 2018  Â·  10Comments  Â·  Source: dotnet/docs

Why the date pattern properties like ShortDatePattern are not localized? E.g dd/mm/aa for Spain


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Area - API Reference doc-provided product-question

All 10 comments

They are localized, @gdiazderadaa. What do you expect the short date pattern for es-ES to be? (I'm wondering if you expect the month to be a Roman numeral. If that's the case, only U+0030 through U+0039 are supported as numeric digits.)

@rpetrusha sorry what I meant is having dd/mm/aaaa for es-ES or gg/mm/aaaa for it-IT, instead of dd/mm/yyyy. Does it make sense now?

Not completely, @gdiazderadaa. "aaaa" is not a recognized custom format string. What happens when you run the following C# code?

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      var cul = new CultureInfo("es-ES");
      Console.WriteLine(cul.DateTimeFormat.ShortDatePattern);

      cul = new CultureInfo("it-IT");
      Console.WriteLine(cul.DateTimeFormat.ShortDatePattern);
   }
}

The result should be dd/MM/yyyy for both cultures.

What would be advantage of having localized custom format strings like that? Are you showing the format strings to your users?

Thanks, @svick. I realize that I was misunderstanding the question. @gdiazderadaa. the custom date and time format strings are predefined language elements (very much like the name of a class, such as System.String, or the name of a language keyword, such as foreach). They cannot be localized.

The idea here is that the format strings provide a standardized grammar that supports output that is both easily localized and easily modifiable. Imagine the difficulty if each culture had not only its own formatting conventions (such as the order of day, month, and year in a date) but also its unique grammar for specifying those date and time elements. It adds an order of complexity that in the end discourages rather than encourages localization.

That said, it is possible to develop an extension implementation to support a customized, culture-specific grammar. For a brief description, see the documentation for the ICustomFormatter interface.

I hope that this finally answers your question, @gdiazderadaa. Under the assumption that it does, I'll close this issue. If not, feel free to respond.

@svick @rpetrusha the main purpose of this is to show a localized placeholder in a DOB field for a multilanguage website.

@gdiazderadaa

First, are you sure your users would understand what the placeholders mean? Isn't there a better way to explain that to them?

If you still think this would be useful, I think it would have to be a new API. You can propose new .Net APIs by creating an issue in the corefx repo, ideally following their API review process.

It's current functionality on a live website so can't change it but just wondering if there was any better way to do it rather than a custom lookup function which uses the culture name and returns the placeholder

A custom lookup based on culture name is probably the best way to do it, @gdiazderadaa.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skylerberg picture skylerberg  Â·  3Comments

sdmaclea picture sdmaclea  Â·  3Comments

stanuku picture stanuku  Â·  3Comments

ygoe picture ygoe  Â·  3Comments

gmatv picture gmatv  Â·  3Comments