Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir,

I have a Server side label Control in my web page.
I wanted to show "Hello, Current time is: 10:30:24 AM. Have a Good Day."

in the label.

What i wrote was:
<asp:Label id="LblTime" runat="server" BackColor="#6600ff" ForeColor="#ffffff" Text="Hello, Current time is: <%=DateTime.Now.ToString() %> Have a Good Day.">

But I am not getting the Time. Kindly Help..
Posted

this should work
C#
<asp:label id="LblTime" runat="server" backcolor="#6600ff" forecolor="#ffffff" >Hello, Current time is:<%=DateTime.Now.ToString() %> Have a Good Day</asp:label>
 
Share this answer
 
v2
Comments
Dinakar Kulkarni 24-Apr-15 11:54am    
Thank You Sir.. :-)
Hi, have a look at Custom Date and Time Format Strings[^] to see how the DateTime.ToString can be formatted.

Something like this should be what you are looking for:

aspx:
ASP.NET
<asp:label id="LblTime" runat="server" backcolor="#6600ff" forecolor="#ffffff" />


code behind:
C#
protected void Page_Load(object sender, EventArgs e)
{
    LblTime.Text = string.concat("Hello, Current time is:",DateTime.Now.ToString("hh:mm:ss tt"), " Have a Good Day");
}


... hope it helps.
 
Share this answer
 
v2
Comments
Dinakar Kulkarni 24-Apr-15 12:01pm    
Thank You So much Sir :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900