我知道DataTime.Now可显示当前时间。如何让秒是变化的,就是时间是往前走的。
解决方案 »
- iis连接网页失败
- 数据绑定的问题
- SQLserver2005与VS2008在Win2008运行与安装问题
- ASP.NET2.0中关于ConfigurationManager
- 读取虚拟串口和读取普通串口有什么不同吗
- 全免费.net源代码,可以在其任意基础上扩充为"一卡通"、"OA"或"其它管理系统"
- 关于两个列表框级联的问题
- 请问动网论坛中的风格,用CSS做,如何在asp.net中动态装载各种风格.CSS刚学CSS.请指教.
- 招聘 .NET实施工程师--北京
- 菜鸟求助:如何弹出自定义错误对话框
- Ajax框架使用调查!!!!!【您使用哪种Ajax框架??】
- FormView控件无法在没有数据时显示的问题。
<script type='text/javascript'>setTimeout('Clock_GetDate()',10);function Clock_GetDate(){var now = new Date();
var yy = now.getYear();
var Month = ((now.getMonth() + 1)<10)?('0'+(now.getMonth() + 1)):(now.getMonth() + 1);
var dd = (now.getDate<10)?('0'+now.getDate()):(now.getDate());
var hh = (now.getHours<10)?('0'+now.getHours()):(now.getHours());
var mm = (now.getMinutes<10)?('0'+now.getMinutes()):(now.getMinutes());
var ss=(now.getSeconds()<10)?('0'+now.getSeconds()):(now.getSeconds());
document.getElementById('Clock').innerHTML=yy + '-' + Month + '-' + dd + ' ' + hh + ':' + mm + ':' + ss;setTimeout('Clock_GetDate()',1000);}
</script>
body部分<span id="Clock"></span>
setTimeout('Clock_GetDate()',10);
function Clock_GetDate()
{
var now = new Date();
var yy = now.getYear();
var Month = ((now.getMonth() + 1)<10)?('0'+(now.getMonth() + 1)):(now.getMonth() + 1);
var dd = (now.getDate<10)?('0'+now.getDate()):(now.getDate());
var hh = (now.getHours<10)?('0'+now.getHours()):(now.getHours());
var mm = (now.getMinutes<10)?('0'+now.getMinutes()):(now.getMinutes());
var ss=(now.getSeconds()<10)?('0'+now.getSeconds()):(now.getSeconds());
document.getElementById('Clock').innerHTML=yy + '-' + Month + '-' + dd + ' ' + hh + ':' + mm + ':' + ss;setTimeout('Clock_GetDate()',1000);}
</script>body
<span id="Clock"></span>
不过想LZ所说的让秒是变化的,就是时间是往前走的,这个要么用JS
还有一中方案就是以前cpp2017(慕白兄) 说的
先取得服务器时间,放在客户端,初始化时比较它与客户端时间的差值,然后 显示客户端的时间+差时.
在前台写个JS脚本就行了,在google,baidu搜时间的JS脚本,恶多
/* Clock and weclome infomation */
function StartClock()
{
time = new Date();
secs = time.getSeconds();
mins = time.getMinutes();
hr = time.getHours();if (hr<10) {hr=" "+hr;}
year =time.getFullYear();
month =time.getMonth()+1;if (month<10) {month="0"+month;}
day =time.getDate();if (day<10) {day=" "+day;}
weekday = GetCHSWeekDay(time.getDay());
if (secs<=9) secs="0"+secs;
if (mins<=9) mins="0"+mins;
divMyClock.innerHTML =" 本地时间(Local Time):"+ month + "-" + day + "-" + year + " " + hr +":" +mins +":"+secs + " " + weekday;
setTimeout('StartClock()',1000);
}
function GetCHSWeekDay(weekday)
{
switch (weekday)
{
case 0: {return "<font color='#ff0000'>Sunday</font>"; break;}
case 1: {return "Monday"; break;}
case 2: {return "Tuesday"; break;}
case 3: {return "Wednesday"; break;}
case 4: {return "Thursday"; break;}
case 5: {return "Friday"; break;}
case 6: {return "<font color='#00ff00'>Saturday</font>"; break;}
}
}
StartClock();
</script>
====================================最终效果: 周六,周日与工作日颜色不同 本地时间(Local Time):09- 6-2007 11:04:10 Thursday