Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Displaying Date in Label

<asp:Label ID="Label1" runat="server" Text='<%# Bind("Date") %>'></asp:Label>

Displays

03.06.2014 10:30:00

How can I display it as 3 Jun 2014 10:30

like image 300
Jude Avatar asked Jun 03 '14 07:06

Jude


4 Answers

This should work:

<asp:Label ID="Label1" runat="server" 
    Text='<%# Eval("Date", "{0:d MMM yyyy HH:mm}") %>'>
</asp:Label>

See: Custom Date and Time Format Strings

like image 84
Tim Schmelter Avatar answered Nov 11 '22 06:11

Tim Schmelter


Try this:

Text='<%# Eval("Date", "{d MMM yyyy hh:mm}") %>'

You can see more format strings here.

like image 43
Liath Avatar answered Nov 11 '22 06:11

Liath


Try this

<asp:Label ID="Label1" runat="server" 
Text='<%# Bind("Date").ToString("d MMM yyyy hh:mm:ss",CultureInfo.CreateSpecificCulture("en-US")) %>'>
</asp:Label>

ref: Custom date time formats

like image 25
Sid M Avatar answered Nov 11 '22 05:11

Sid M


Maybe something like this:

Bind("Date").ToString("d MMM yyyy hh:mm")

You could also do this:

string.Format("{0:d MMM yyyy hh:mm}",Bind("Date"))
like image 21
Arion Avatar answered Nov 11 '22 07:11

Arion