c# - 使用 C# 和 InsertParameters (ASP.NET) 没有时间的日期

标签 c# asp.net date

我在 ASP.NET 中使用此 C# 代码通过“AccessDataSource”在 GridView 中显示没有时间的日期:

var f = DateTime.Now;
string dwt = f.ToString("dd/MM/yyyy");

AccessDataSource3.InsertParameters["Date birth"].DefaultValue = dwt;
AccessDataSource3.Insert();

但是,应用程序仍会像这样显示日期:dd/MM/yyyy hh:mm:ss

我也试过这个:

string f = DateTime.Now.ToString("dd.MM.yyyy");
string[] v = f.Split(new char[] { ' ' });

AccessDataSource3.InsertParameters["Date birth"].DefaultValue = ""+v[0];
AccessDataSource3.Insert();

也不行。 也许这些代码不起作用,因为我忘记向其中添加一些东西?

最佳答案

试试 ToShortDateString() 方法

var f = DateTime.Now;
string dwt = f.ToShortDateString();

这只会导致 date17/06/2016

关于c# - 使用 C# 和 InsertParameters (ASP.NET) 没有时间的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37876023/

相关文章:

javascript - 到达方法主体时传递给 WebApi 方法的参数为 null

C# Parallel.For 不执行每一步

c# - 列表中的SelectMany:“无法根据使用情况推断类型自变量”

c# - .net 中继器与子中继器

c# - .Net-通过Outlook发送的电子邮件应更新数据库

mysql - 有没有办法改变日期格式?

Javascript 新日期返回错误的年份

c# - ConcurrentDictionary 上的 TryGetValue 是原子的吗?

python - 根据日期对 CSV 文件进行排序

c# - 无法修改数据集