可以用lable来作为显示当前时间的控件吗
比如显示“今天是2012年2月28日 星期二”
但是怎么与当前时间关联呢
谢大侠~
------解决方案--------------------------------------------------------
asp.net页放个Label,比如ID:lblNowDate
.cs文件Load事件中---->lblNowDate.Text = DateTime.Now.ToString();
当然时候格式化,可以根据你的需求自己来
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
计时器不一定要每秒都要更新啊,参数是1000的时候就是一秒,你可以更改这个参数。
如果你不添加计时器,就不能动态更新时间,也就是时间是不动的。
你可以用一个时间变量存储DateTime.Now()取下的时间,这时间变量里面年月日时分秒都有了,你可以按需求增减,在变量后一点就出来它的属性
------解决方案--------------------------------------------------------
添加个label,添加个timer
this.lblStatus.Text = "系统当前时间:" + DateTime.Now.ToString();
this.systime.Interval = 1000;//每个1s更新时间
写tick事件
private void systime_Tick(object sender, EventArgs e)
{
this.lblStatus.Text = "系统当前时间" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo);
}
------解决方案--------------------------------------------------------
- C# code
<b>现在是:<span id="thetime"></span></b><script type="text/javascript">var timerID = null;var timerRunning = false;function stopclock() { if (timerRunning) clearTimeout(timerID); timerRunning = false;}function startclock() { stopclock(); showtime();}function showtime() { var now = new Date(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds() var timeValue = now.getFullYear() + "年" + (now.getMonth() + 1) + "月" + now.getDate() + "日 " timeValue += hours timeValue += ((minutes < 10) ? ":0" : ":") + minutes timeValue += ((seconds < 10) ? ":0" : ":") + seconds document.getElementById("thetime").innerHTML = timeValue; timerID = setTimeout("showtime()", 1000); timerRunning = true;}</script>