看似简单。我需要将DateTime对象转换为没有时间戳的字符串。如何将DateTime对象转换为仅使用C#日期的字符串?
这给了我日期和时间。而我无法弄清楚如何获得日期。
startDate = Convert.ToString(beginningDate);
此输出:2011年10月1日12:00:00 AM
我需要的是:2011年10月1日作为一个字符串
任何帮助表示赞赏。
看似简单。我需要将DateTime对象转换为没有时间戳的字符串。如何将DateTime对象转换为仅使用C#日期的字符串?
这给了我日期和时间。而我无法弄清楚如何获得日期。
startDate = Convert.ToString(beginningDate);
此输出:2011年10月1日12:00:00 AM
我需要的是:2011年10月1日作为一个字符串
任何帮助表示赞赏。
使用
string startdate = beginningDate.ToShortDateString();
为MSDN参考看到http://msdn.microsoft.com/en-us/library/system.datetime.toshortdatestring.aspx
string startDate = beginningDate.ToShortDateString();
还检查出DateTime
的.ToString
方法,它接受format string。例如:
string startDate = beginningDate.ToString("d");
对于ideone.com来说为+1 – renatoargh
你可以做这样的事情;
DateTime dt = beginningDate; StringBuilder sbDate = Convert.toString(dt.year); //以及对其他月份和日期
可能重复的[如何仅显示日期组件](http://stackoverflow.com/questions/ 4111606/how-to-date-date-with-just-the-date-component) –