看似简单。我需要将 DateTime 对象转换为没有时间戳的字符串。
这给了我日期和时间。而且我不知道如何获得日期。
startDate = Convert.ToString(beginningDate);
输出:10/1/2011 12:00:00 AM
我需要它是:10/1/2011 作为字符串
任何帮助表示赞赏。
最佳答案
string startDate = beginningDate.ToShortDateString();
另请查看
.ToString
DateTime
上的方法这需要 format string .例如:string startDate = beginningDate.ToString("d");
示例: http://ideone.com/tpyZy
关于c# - 如何使用 C# 将 DateTime 对象转换为仅包含日期的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7622818/