Possible Duplicate:
Format date in C#
I want to display the date in the formatMay 16,开发者_JS百科 2011
. I have used format String.Format("{0:D}"
by which i got the output like Monday, May 16, 2011
.
So please any one tell me how i will be able to show date time in the following formatMay 16, 2011
Thanks in advance
"{0:MMMM d, yyyy}"
Here is the documentation.
Custom Date and Time Format Strings
DateTime dt = DateTime.Now;
String.Format("{0:MMMM d, yyyy}", dt);
This should to the trick?
EDIT: Here are some handy examples! http://www.csharp-examples.net/string-format-datetime/
DateTime.Now.ToString("MMM dd, yyyy");
Try this
String.Format("{0:MMMM dd, yyyy}", someDate)
If you use D for a date format the format will be taken from the Regional settings in the control panel of the machine. You could change the date format of the machine the software is running on. (Or hand code a format).
There doesn't appear to be a Standard Date and Time Format String that matches your desired format, so you need to construct a Custom Date and Time Format String
This should do the trick:
string.Format("{0:MMMM dd, yyyy}", value)
Or alternatively
value.ToString("MMMM dd, yyyy")
- MMMM - The full name of the month, e.g. June (en-US)
- dd - The day of the month, from 01 through 31
- yyyy - The year as a four-digit number.
精彩评论