如何只在asp.net中显示时间? [英] How do I display only the time in asp.net?

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

问题描述

这是我现在的代码:



This is the code I have now:

<script  runat="server">
Sub Page_Load
lbl1.Text="The date and time is " & now ()
End Sub
</script>
<html>
<body>
<form  runat="server">
<h3><asp:label id="lbl1" runat="server" /></h3>
</form>
</body>
</html>





我想修改&现在只显示时间,没有日期。我该怎么做?



I want to modify & now to display only the time, without the date. How do I do this?

推荐答案

使用 DateTime.ToString [ ^ ]方法。



您可以使用标准日期和时间格式字符串 [ ^ ]获取时间:
Use the DateTime.ToString[^] method.

You can use the Standard Date and Time Format Strings[^] to get the time:
DateTime.Now.ToString( "T" )

自定义日期和时间格式字符串 [ ^ ]:

DAteTime.Now.ToString( "HH:mm:ss" )


因为你只需要显示时间而且你有asp.net页面,它为你提供了模型背后的代码的灵活性,所以你可以使用表单加载部分服务器端代码并​​简单地写以下



as you just need to display time and you have asp.net page which gives you the flexibility of code behind model so you can use form load part of serverside code and simply write the following

Protected void Form_Load(object sender,EventArgs e)
{
lbl1.Text=DateTime.Now.ToShortTimeString();
}





它会给你想要的结果......



it will give you the desired result...


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

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