Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

Setting Date format yyyyMMdd through specify Culture Name

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

Upvotes: 1

Views: 8057

Answers (3)

Yordan Georgiev
Yordan Georgiev

Reputation: 5430

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:

Upvotes: 1

Thomas Levesque
Thomas Levesque

Reputation: 292425

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;

Upvotes: 6

Marc Gravell
Marc Gravell

Reputation: 1062780

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?

Upvotes: 4

Related Questions