Localising date layout descriptors

What is the most effective means to localise a date layout descriptor?

As any person from a society which does not make use of the mm/dd/yyyy layout recognizes, it is frustrating to need to enter days in this layout. The.NET structure gives some great localisation assistance, so it's unimportant to parse days according to the customers society, yet you usually intend to additionally display a handy tip regarding the layout called for (specifically to compare yy and also yyyy which is compatible in the majority of societies).

What is the most effective means to do this in such a way that make good sense to the majority of customers (e.g. dd/M/yyy is perplexing as a result of the adjustment in instance and also the changing in between one and also 2 letters).

2019-05-05 00:12:18
Source Share
Answers: 6

The problem with global criteria is that virtually noone utilizes them. I attempt where I can, yet I am compelled to make use of dd/mm/yyyy virtually anywhere in the real world, which suggests I am so made use of to it it's constantly an aware procedure to make use of ISO - 8601. For most of individuals that do not also attempt to make use of ISO - 8601 it's also worse. If you can internationalize where you can, I assume it's a wonderful benefit.

2019-05-08 21:29:42

I need to concur with the OP 'incorrect' days actually container with my DD/MM/YYYY training and also I locate ISO 8601 days and also times exceptionally very easy to collaborate with. For as soon as the typical obtained it appropriate and also engtech has the noticeable solution that does not call for localisation.

I was mosting likely to report the birthday celebration input kind on pile overflow as a bug as a result of just how much of an aching thumb it is to most of the globe.

2019-05-08 18:41:54

A brief kind is hassle-free and also aids stay clear of punctuation blunders. Center as relevant, yet make certain to present the anticipated layout (do not leave the customer blind). Give a date - picker control as an optional assistant to completing the area.

As an added, on - the - fly parsing and also display screen of the date in lengthy kind could aid also.

2019-05-08 10:49:09

Here is my existing method. Any kind of pointers?

Regex singleMToDoubleRegex = new Regex("(?<!m)m(?!m)");
Regex singleDToDoubleRegex = new Regex("(?<!d)d(?!d)");
CultureInfo currentCulture = CultureInfo.CurrentUICulture;

// If the culture is netural there is no date pattern to use, so use the default.
if (currentCulture.IsNeutralCulture)
    currentCulture = CultureInfo.InvariantCulture;

// Massage the format into a more general user friendly form.
string shortDatePattern = CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern.ToLower();
shortDatePattern = singleMToDoubleRegex.Replace(shortDatePattern, "mm");
shortDatePattern = singleDToDoubleRegex.Replace(shortDatePattern, "dd");
2019-05-08 05:33:00

How around offering the layout (mm/dd/yyyy or dd/mm/yyyy) adhered to by a hard copy these days's date in the customer's society. MSDN has a write-up on formatting a DateTime for the person's culture, making use of the CultureInfo object that could be handy in doing this. A mix of the layout (which most individuals know with) incorporated with the existing date stood for because layout needs to suffice of an idea to the individual on just how they need to enter the date. (Also include a schedule control for those that still cant number it out).

2019-05-08 05:31:15

Just use ISO-8601. It's a global criterion.

Date and time (current at page generation) expressed according to ISO 8601:
Date:                           2014-07-05
Combined date and time in UTC:  2014-07-05T04:00:25+00:00
Week:                           2014-W27
Date with week number:          2014-W27-6
Ordinal date:                   2014-186
2019-05-08 04:37:52