日期时间显示格式 [英] Date Time Display Format
本文介绍了日期时间显示格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友,
我正在网格视图中显示一组数据.
datetime字段显示为"5/30/2012 12:00:00 AM",但我想将其格式化为DD-MM-YYYY.
我是.Net的新手.请引导我格式化此文件.
问候,
AP
Dear Friends,
I am displaying set of data in Grid View.
The datetime field is displayed as "5/30/2012 12:00:00 AM" but I want to format it to DD-MM-YYYY.
I am new to .Net. Kindly guide me in formating this.
Regards,
AP
推荐答案
^ ]
你也可以试试这个
Check THis[^]
you can try this also
<asp:TemplateField HeaderText="Departure Date">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("DepartDate",
"{0:dd-mm-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
如果您使用的是BoundField
,只需执行以下操作:
If you''re using aBoundField
, simply do as follows:
<asp:boundfield datafield="Your_Date_Column" dataformatstring="{0:MMMM d, yyyy}" htmlencode="false" xmlns:asp="#unknown" />
只需确保将HtmlEncode属性设置为False,否则它将不起作用.
看看:如何使用ASP.NET在GridView中设置日期格式 [
Just make sure you set the HtmlEncode attribute to False or it won''t work.
Have a look: How To Set a Date Format In GridView Using ASP.NET[^]
Arunprasath,
设置绑定到日期的列的DataFormatString属性,如下面的网格示例代码所示:
Hi Arunprasath ,
set DataFormatString Property of the column that is bound to date as below sample code for a grid:
<asp:gridview id="gvParent" runat="server" xmlns:asp="#unknown">
<columns>
<asp:boundfield datafield="Leave_From_Date" headertext="Date From">DataFormatString = "{0:dd-MM-yyyy}" />
</asp:boundfield></columns>
</asp:gridview>
这可以解决问题.
快乐编码:)
this will do the trick.
Happy Coding :)
这篇关于日期时间显示格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文