C# 日、月、日、年的日期格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18988921/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 13:48:44  来源:igfitidea点击:

Date Format in Day, Month Day, Year

c#datetime

提问by Nate Pet

I am using c#.

我正在使用 C#。

I know I can use

我知道我可以使用

    ToLongDateString() 

to show something like:

显示如下内容:

   Friday, February 27, 2009

What I like to do instead is show something like:

我喜欢做的是展示类似的东西:

  February 27, 2009

I looked around but did not find what to use to display in such a format.

我环顾四周,但没有找到以这种格式显示的内容。

采纳答案by Vajda Endre

Read this: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

阅读:http: //msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Try to use:

尝试使用:

thisDate1.ToString("MMMM dd, yyyy");

回答by King King

var s = yourDateTime.ToString("MMMM dd, yyyy");

Check out this Custom DateTime format string

查看此自定义日期时间格式字符串

回答by p.s.w.g

Something like this should work:

这样的事情应该工作:

new DateTime(2009, 02, 27).ToString("MMMM dd, yyyy") // February 27, 2009

Further Reading

进一步阅读

UpdateIn C# 6 and later, you can also use string interpolation, like so:

更新在 C# 6 及更高版本中,您还可以使用字符串插值,如下所示:

$"{new DateTime(2009, 02, 27):MMMM dd, yyyy}" // February 27, 2009

回答by Samuel

Try using this: http://www.csharp-examples.net/string-format-datetime/The examples are all very readable and easy.

尝试使用这个:http: //www.csharp-examples.net/string-format-datetime/这些例子都非常易读和容易。