Wondering
Wondering

Reputation: 5076

way to get exact below format of current date

Is there any way to get exact below format of current date- 18 Aug 2010. I tried -

 string dt = DateTime.Now.ToShortDateString().ToString();
  dt = dt.Replace("-", " ");//return 18 Aug 10.

But I want the exact format: 18 Aug 2010

Thanks

Upvotes: 0

Views: 349

Answers (6)

Nicole Calinoiu
Nicole Calinoiu

Reputation: 20982

If you want to always use the English month abbreviation regardless of the thread culture, you should specify the formatting culture as well. e.g.:

DateTime.Now.ToString("dd MMM yyyy", CultureInfo.InvariantCulture)

Upvotes: 2

Jake1164
Jake1164

Reputation: 12349

string dt = DateTime.Now.ToString("dd MMM yyyy");

Upvotes: 0

Dan Tao
Dan Tao

Reputation: 128317

string formattedDate = DateTime.Now.ToString("dd MMM yyyy");

Reference: Custom DateTime Format Strings (MSDN).

Upvotes: 1

fearofawhackplanet
fearofawhackplanet

Reputation: 53378

.ToString("dd MMM yyyy");

or

.ToString("d MMM yyyy");

Depending on if you want the day part as for example "08 Aug" or "8 Aug"

Upvotes: 2

msergeant
msergeant

Reputation: 4801

string dt = DateTime.Now.ToString("d MMM yyyy");

Upvotes: 0

Dave McClelland
Dave McClelland

Reputation: 3413

DateTime.Now.ToString("d MMM yyyy");

This link has more information on formatting DateTime in C#

Upvotes: 1

Related Questions