我知道DataTime.Now可显示当前时间。如何让秒是变化的,就是时间是往前走的。

解决方案 »

  1.   

    这个.net是有些难实现了。JS可以。
      

  2.   

    用JSJS部分
    <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>
      

  3.   

    太乱了,重新整理下给你<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>
      

  4.   

    获取服务器端时间:System.DateTime.Now
    不过想LZ所说的让秒是变化的,就是时间是往前走的,这个要么用JS
    还有一中方案就是以前cpp2017(慕白兄) 说的
    先取得服务器时间,放在客户端,初始化时比较它与客户端时间的差值,然后 显示客户端的时间+差时.
      

  5.   

    用ajax实现会好一些,里面有timer控件.放在网页上就可以用...
      

  6.   

    顶下
    在前台写个JS脚本就行了,在google,baidu搜时间的JS脚本,恶多
      

  7.   

    我还是建议用JavaScript(JS)比较好
      

  8.   

    <script language="javascript">
    /* Clock and weclome infomation */
    function StartClock()
    {
    time = new Date();
    secs = time.getSeconds();
    mins = time.getMinutes();
    hr = time.getHours();if (hr<10) {hr="&nbsp;"+hr;}
    year =time.getFullYear();
    month =time.getMonth()+1;if (month<10) {month="0"+month;}
    day =time.getDate();if (day<10) {day="&nbsp;"+day;}
    weekday = GetCHSWeekDay(time.getDay());
    if (secs<=9) secs="0"+secs;
    if (mins<=9) mins="0"+mins;
    divMyClock.innerHTML ="&nbsp;本地时间(Local Time):"+ month + "-" + day + "-" + year + "&nbsp;" + hr +":" +mins +":"+secs + "&nbsp;" + 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