在Gridview中仅显示日期,但不显示时间 [英] Display only Date, But NOT time in Gridview
问题描述
亲爱的朋友,
我有用户表,
我已绑定并显示在GRIDVIEW中.
在那我有像签发日期和到期日期这样的字段.
它显示了这样的日期和时间2012/4/29上午12:00:00
我只需要显示日期而不是时间
我想在gridview 29/4/2012中这样显示
请给我建议.该怎么做?
谢谢,
Dear Frnds,
I have table with Users,
I have binded and displayed in GRIDVIEW.
In that i have Fields like Issue date and Expiry Date.
it is displaying date and time like this 4/29/2012 12:00:00 AM
Just i need to display only date not time
I want to display like this in gridview 29/4/2012
Please suggest me. how to do this ?
Thanks,
推荐答案
您可以使用带掩码的ToString()方法:
You can use the ToString() method with a mask:
ToString("MM/dd/yyyy");
>
或者您可以使用
OR you can use
.ToShortDateString();
或者,如果您使用的是边界域,请尝试以下操作:
OR if you are using boundfield then try following:
<asp:BoundField HeaderText="Date" DataField="MyDate"
DataFormatString="{0:MM/dd/yy}">
或尝试以下操作:
将DataColumn设置为仅日期而不是日期时间
OR try following:
Setting DataColumn to just a Date not a Datetime
您可以使用Dataformatstring
检查此链接
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx [ http://www.ezineasp.net/post/ASP-Net-Gridview- DataFormatString-Date-Format.aspx [ ^ ]
最好的问候
M.Mitwalli
Hi ,
You can useDataformatstring
Check this link
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx[^]
http://www.ezineasp.net/post/ASP-Net-Gridview-DataFormatString-Date-Format.aspx[^]
Best Regards
M.Mitwalli
您可以在显示数据时使用string.Format()方法:-
You can use string.Format() method while displaying data :-
GRIDVIEW.Rows[rowNum].Cells[colName].Value = string.Format("{0:dd/MM/yyyy}",29/04/2012 12:00:00 AM);
希望这项工作:)
Hope this work :)
这篇关于在Gridview中仅显示日期,但不显示时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!