简体   繁体   中英

ASP.net date formatting

I have bound date fields(datetime type column values) to my Grid. In the grid, the column definition is like so My code is:

<asp:Label id="lblFromTimeForTeacher" runat="server" Text='<%# Eval("FromTime", "{0:hh/mm}")%>' Visible="false" Width="99%" />

Right now, the label text is 08-45 . Could someone please tell how can I get the label text as 08:45 ? Thanks in advance.

Custom DateTime formatting here . In your case just change to Convert.ToDateTime(Eval("FromTime")).ToString("hh:mm")

Try the following

<asp:Label ID="lblFromTimeForTeacher" runat="server" Text='<%# Eval("FromTime", "{0:hh:mm}")%>' Visible="false" Width="99%" />

if you want in "4:05 PM" format then try the following

<asp:Label ID="lblFromTimeForTeacher" runat="server" Text='<%# Eval("FromTime", "{0:t}")%>' Visible="false" Width="99%" />

For more you can review This Link hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM