[英]C# Date Time Formatting
How can I convert my DateTime
object to this kind of date format: 如何将我的DateTime
对象转换为这种日期格式:
I am currently doing object.GetDateTimeFormats('D')[1].ToString() 我正在做object.GetDateTimeFormats('D')[1] .ToString()
This is giving me January 31, 2012. But I should be able to get these two things: 这是给我2012年1月31日。但我应该能够得到这两件事:
Use a custom DateTime
formatting string: 使用自定义DateTime
格式字符串:
// Returns Jan 31, 2012
myDateTimeObject.ToString("MMM dd, yyyy");
// Returns 31 January, 2012
myDateTimeObject.ToString("dd MMMM, yyyy");
All of the custom date/time formats are listed here. 此处列出了所有自定义日期/时间格式。
All types of date formatting you need. 您需要的所有类型的日期格式。
Just select the correct string format you need: 只需选择所需的正确字符串格式:
Console.WriteLine(DateTime.Now.ToString("d-MMM-yy"));
18-Jan-18 18-JAN-18
Console.WriteLine(DateTime.Now.ToString("d-MM-yy"));
18-1-18 18-1-18
Console.WriteLine(DateTime.Now.ToString("d-MM-yyyy"));
18-1-2018 18-1-2018
MoreDetails :- http://www.code-sample.net/CSharp/Format-DateTime 更多详细信息 : - http://www.code-sample.net/CSharp/Format-DateTime
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.