way to get exact below format of current date
Is the开发者_开发技巧re 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
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)
.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"
DateTime.Now.ToString("d MMM yyyy");
This link has more information on formatting DateTime in C#
string formattedDate = DateTime.Now.ToString("dd MMM yyyy");
Reference: Custom DateTime Format Strings (MSDN).
string dt = DateTime.Now.ToString("d MMM yyyy");
string dt = DateTime.Now.ToString("dd MMM yyyy");
精彩评论