c# - 如何使用 C# 将 DateTime 对象转换为仅包含日期的字符串?

标签 c# asp.net

看似简单。我需要将 DateTime 对象转换为没有时间戳的字符串。

这给了我日期和时间。而且我不知道如何获得日期。

        startDate = Convert.ToString(beginningDate);

输出:10/1/2011 12:00:00 AM

我需要它是:10/1/2011 作为字符串

任何帮助表示赞赏。

最佳答案

查看 .ToShortDateString()

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/

相关文章:

c# - 这是什么代码 : Func < T, string > 我不明白

javascript - 关注第一个asp :textbox in each bootstrap tab when clicking tab link

.net - 路由与 URL 重写 (IIS7) 性能

c# - 如何从数组中随机选择一行?

c# - 为什么这会抛出OutOfMemory?

c# - 如何动态检查数组中的索引是否存在?

c# - 如何获取 IdentityServer4 登录用户的列表?

c# - 使用 configurationmanager 读取多个 web.config 文件

asp.net - .NET 中的垃圾收集器

c# - Microsoft.Azure.Storage.StorageException : The account being accessed does not support http