我有一个文本框,应该以dd / MM / yyyy格式插入日期。我只能找到并使用的是smalldatetime或datetime。我选择smalldatetime,显示的数据就像是01/07/2011 12:00:00 AM。任何相关的代码将其排序为仅显示01/07/2011(没有时间)?
SqlJobMaster.InsertParameters [“StartDate”]。DefaultValue = txtStartDate.Text.ToString();
ASP.NET
开始日期
答案 0 :(得分:2)
使用ToString("dd/MM/yyyy");
。然后它将按照您希望的方式进行格式化。
答案 1 :(得分:1)
我没有在ASP.NET中使用GridView
,但根据this article,您基本上需要为相关的BoundField
设置DataFormatString
属性,例如到"{0:dd/MM/yyyy}"
。但是,如果您的应用要用于多种文化,您应该考虑文化差异:"{0:d}"
是一般的“当前文化的短日期模式”格式字符串。
答案 2 :(得分:0)
类似的东西:
String.Format("{0:MM/dd/yyyy}", dt);
答案 3 :(得分:0)
您可以尝试:
DateTime dt = DateTime.Parse(txtDate.Text);
SqlJobMaster.InsertParameters["StartDate"].DefaultValue = dt.ToShortDateString();