开发者

How to display DateTime with just the date component

开发者 https://www.devze.com 2023-01-23 14:06 出处:网络
<asp:Label ID=\"dateLabel\" runat=\"server\" Text=\'<%# Eval(\'SomeDate\') %> /> This displays showing the date and time. However I just want to display the date.
<asp:Label ID="dateLabel" runat="server" Text='<%# Eval('SomeDate') %> />

This displays showing the date and time. However I just want to display the date.

I'm aware that in the code behind you can write SomeDate.ToString("dd MM yyyy");

However I want a way of 开发者_JAVA百科doing this by changing the code in the tag instead.

Is this possible?


Try <%# Eval("SomeDate","0:dd-MMM-yyyy") %> or of course any date format you like.


Not really an answer to your requirement, but in you code behind you can also do

string formattedDate = SomeDate.ToShortDateString();

and in your tag, just display the formatted date

<asp:Label ID="dateLabel" runat="server" Text='<%# Eval('formattedDate') %> />
0

精彩评论

暂无评论...
验证码 换一张
取 消