Question

I want to set user date format yyyyMMdd using culture name. Which culture name have to specify to accomplish this?

Was it helpful?

Solution

Why wouldn't you use the format specifier?

string s = DateTime.Today.ToString("yyyyMMdd");

I'm not aware of any pre-rolled cultures that use this specifier. You could perhaps roll your own culture?

OTHER TIPS

You can create your own culture using the CultureAndRegionInfoBuilder class (in assembly sysglobl). But it may be overkill for your need...

Another, simpler solution : create a new instance of CultureInfo based on the current culture, and assign it a custom DateTimeFormatInfo :

DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
dtfi.ShortDateTimePattern = "yyyyMMdd";
CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name);
ci.DateTimeFormat = dtfi;

This link might help you in understanding number and DateTime formatting as well as culture specific formatting overriding. It basically demonstrates it by remodifying the msdn code examples:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top