DateTime format in c# [duplicate]

一曲冷凌霜 提交于 2019-12-06 16:46:14
Daniel A. White
"{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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!