修复日期格式以不在BoundColumn上显示时间

时间:2017-07-18 10:58:55

标签: c# asp.net datagrid date-formatting boundcolumn

我正在尝试将日期格式更改为仅在DataGrid上的BoundColumn中显示日期而不是时间,但到目前为止我没有尝试过任何工作。

<asp:BoundColumn DataField="InvoiceDate" HeaderText="Date" DataFormatString = "{0:MM-dd-yyyy}"/>

我也尝试过:

DataFormatString="{0:dd-M-yyyy}"
DataFormatString="{0:d}"
DataFormatString="{0:MMM-d-yyy}"

1 个答案:

答案 0 :(得分:0)

这是我在表格中使用的格式字符串,它只显示日期:

<asp:BoundField HeaderText="Date" DataField="Date"
     SortExpression="Date" DataFormatString="{0:dd/MM/yyyy}" />

一个有趣的警告是,这会将日期呈现为使用dd-MM-yyyy格式化,但区域设置可能会在此处发挥作用。