Setting the yyyyMMdd date format by defining the culture name

I want to set the date format of user yyyyMMdd using culture name. What culture name must be specified to accomplish this?

+1


a source to share


3 answers


Why don't you use a format specifier?

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

      



I am not aware of any pre-rolled crops that use this specifier. Can you possibly flip your own culture?

+4


a source


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

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



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

      

+6


a source


+1


a source







All Articles