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:
- How do you calculate someone's age based on datetime?
- Difference between Math.Floor() and Math.Truncate().
- Anatomy of a memory leak -'memory leak'
- Do you like compression of files? How do you decompress them?
- How can I sync my SVN revision number with my ASP.NET web site?
- What is the catch all algorithm?
- How do you sort a dictionary by value?
- If a.net Embedded Database runs on a network. Embedded Database can run off a network.
- How can I create an object instance from a Type?
- How can I make my projects international in india?
- How should I limit the size of the QueueT> in.NET?
- How do you check for file locks?
- Can multiple dataContext classes be a good use of data?
- What is the most efficient way to test a specific test case?
- How do you change a master page background to the code behind your content page?