DateTime format in c# [duplicate]

怎甘沉沦 提交于 2019-12-23 03:32:23

问题


Possible Duplicate:
Format date in C#

I want to display the date in the formatMay 16, 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


回答1:


"{0:MMMM d, yyyy}"

Here is the documentation.

Custom Date and Time Format Strings




回答2:


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/




回答3:


DateTime.Now.ToString("MMM dd, yyyy");



回答4:


Try this

     String.Format("{0:MMMM dd, yyyy}", someDate)



回答5:


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).




回答6:


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.


来源:https://stackoverflow.com/questions/7176580/datetime-format-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!