views:

1403

answers:

3

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

+4  A: 

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?

Marc Gravell
If I set the culture name, don't need to handle MaskedEditExtender and CalendarExtender and no other handling required
Muhammad Akhtar
I don't know of a way to do it just using the culture...
Marc Gravell
@Muhammad: by setting the culture you will also affect other things, such as numeric formats (thousand separator, decimal character), currency symbols and such.
Fredrik Mörk
yes, you are right, but this time I need only date format.
Muhammad Akhtar
the issue here is , MaskedEditExtender only validate when we set culture property, rather only set date format.
Muhammad Akhtar
+4  A: 

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;
Thomas Levesque
+1  A: 

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:

YordanGeorgiev