The best resources for developers

Localising Date format descriptors: A set of localised descriptors for localising the date format in an existing format.

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");

Tags: .net globalization date internationalization

Source: By ICR as answer to the question

This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 3.0

Related code-snippets: