如何在标签上显示时间? [英] How to show time in a label?

查看:282
本文介绍了如何在标签上显示时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生,



我的网页上有一个服务器端标签控件。

我想表示你好,当前时间是:10:3​​0:24 AM。祝你有个美好的一天。



in the标签。



我写的是:

< asp:Label id =LblTimerunat =serverBackColor =# 6600ffForeColor =#ffffffText =你好,当前时间是:<%= DateTime.Now.ToString()%>祝你有个美好的一天。>



但我没有得到时间。请帮助..

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..

推荐答案

这应该工作

this should work
<asp:label id="LblTime" runat="server" backcolor="#6600ff" forecolor="#ffffff" >Hello, Current time is:<%=DateTime.Now.ToString() %> Have a Good Day</asp:label>


您好,请查看自定义日期和时间格式字符串 [ ^ ]看看如何格式化DateTime.ToString。



这样的东西应该是你想要的:



aspx:

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:label id="LblTime" runat="server" backcolor="#6600ff" forecolor="#ffffff" />





代码落后:



code behind:

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.


这篇关于如何在标签上显示时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆