C#日期时间格式 [英] C# Date Time Formatting
本文介绍了C#日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将我的 DateTime
对象转换为这种日期格式:
How can I convert my DateTime
object to this kind of date format:
- Mmm dd yyyy
- dd月yyyy
我当前正在执行object.GetDateTimeFormats( 'D')[1] .ToString()
I am currently doing object.GetDateTimeFormats('D')[1].ToString()
这给了我2012年1月31日。但是我应该能够得到这两件事:
This is giving me January 31, 2012. But I should be able to get these two things:
- 2012年1月31日
- 2012年1月31日
推荐答案
使用自定义的 DateTime
格式化字符串:
Use a custom DateTime
formatting string:
// 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.
这篇关于C#日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文