利用asp。net如何提取服务器端时间,不停的显示在浏览器上?(100分)

  • 主题发起人 主题发起人 夏敏
  • 开始时间 开始时间

夏敏

Unregistered / Unconfirmed
GUEST, unregistred user!
利用asp。net如何提取服务器端时间,不停的显示在浏览器上?
 
挂历时间显示:
<SCRIPT language=JavaScript>
function Year_Month(){
var now = new Date();
var yy = now.getYear();
var mm = now.getMonth()+1;
var cl = '<font color=&quot;#0000df&quot;>';
if (now.getDay() == 0) cl = '<font color=&quot;#c00000&quot;>';
if (now.getDay() == 6) cl = '<font color=&quot;#00c000&quot;>';
return(cl + yy + '年' + mm + '月</font>');
}
function Date_of_Today(){
var now = new Date();
var cl = '<font color=&quot;#ff0000&quot;>';
if (now.getDay() == 0) cl = '<font color=&quot;#c00000&quot;>';
if (now.getDay() == 6) cl = '<font color=&quot;#00c000&quot;>';
return(cl + now.getDate() + '</font>');
}
function Day_of_Today(){
var day = new Array();
day[0] = &quot;星期日&quot;;
day[1] = &quot;星期一&quot;;
day[2] = &quot;星期二&quot;;
day[3] = &quot;星期三&quot;;
day[4] = &quot;星期四&quot;;
day[5] = &quot;星期五&quot;;
day[6] = &quot;星期六&quot;;
var now = new Date();
var cl = '<font color=&quot;#0000df&quot;>';
if (now.getDay() == 0) cl = '<font color=&quot;#c00000&quot;>';
if (now.getDay() == 6) cl = '<font color=&quot;#00c000&quot;>';
return(cl + day[now.getDay()] + '</font>');
}
function CurentTime(){
var now = new Date();
var hh = now.getHours();
var mm = now.getMinutes();
var ss = now.getTime() % 60000;
ss = (ss - (ss % 1000)) / 1000;
var clock = hh+':';
if (mm < 10) clock += '0';
clock += mm+':';
if (ss < 10) clock += '0';
clock += ss;
return(clock);
}
function refreshCalendarClock(){
document.all.calendarClock1.innerHTML = Year_Month();
document.all.calendarClock2.innerHTML = Date_of_Today();
document.all.calendarClock3.innerHTML = Day_of_Today();
document.all.calendarClock4.innerHTML = CurentTime();
}
var webUrl = webUrl;
document.write('<table border=&quot;0&quot;
cellpadding=&quot;0&quot;
cellspacing=&quot;0&quot;><tr><td>');
document.write('<table id=&quot;CalendarClockFreeCode&quot;
border=&quot;0&quot;
cellpadding=&quot;0&quot;
cellspacing=&quot;0&quot;
width=&quot;60&quot;
height=&quot;70&quot;
');
document.write('style=&quot;position:absolute;visibility:hidden&quot;
bgcolor=&quot;#eeeeee&quot;>');
document.write('<tr><td align=&quot;center&quot;><font ');
document.write('style=&quot;cursor:hand;color:#ff0000;font-family:宋体;font-size:14pt;line-height:120%&quot;
');
if (webUrl != 'netflower'){
document.write('</td></tr><tr><td align=&quot;center&quot;><font ');
document.write('style=&quot;cursor:hand;color:#2000ff;font-family:宋体;font-size:9pt;line-height:110%&quot;
');
}
document.write('</td></tr></table>');
document.write('<table border=&quot;0&quot;
cellpadding=&quot;0&quot;
cellspacing=&quot;0&quot;
width=&quot;61&quot;
bgcolor=&quot;#C0C0C0&quot;
height=&quot;70&quot;>');
document.write('<tr><td valign=&quot;top&quot;
width=&quot;100%&quot;
height=&quot;100%&quot;>');
document.write('<table border=&quot;1&quot;
cellpadding=&quot;0&quot;
cellspacing=&quot;0&quot;
width=&quot;58&quot;
bgcolor=&quot;#FEFEEF&quot;
height=&quot;67&quot;>');
document.write('<tr><td align=&quot;center&quot;
width=&quot;100%&quot;
height=&quot;100%&quot;
>');
document.write('<font id=&quot;calendarClock1&quot;
style=&quot;font-family:宋体;font-size:7pt;line-height:120%&quot;> </font><br>');
document.write('<font id=&quot;calendarClock2&quot;
style=&quot;color:#ff0000;font-family:Arial;font-size:14pt;line-height:120%&quot;> </font><br>');
document.write('<font id=&quot;calendarClock3&quot;
style=&quot;font-family:宋体;font-size:9pt;line-height:120%&quot;> </font><br>');
document.write('<font id=&quot;calendarClock4&quot;
style=&quot;color:#100080;font-family:宋体;font-size:8pt;line-height:120%&quot;><b> </b></font>');
document.write('</td></tr></table>');
document.write('</td></tr></table>');
document.write('</td></tr></table>');
setInterval('refreshCalendarClock()',1000);
</SCRIPT>
 
这个用JS来做比较好!
 
提取服务端时间会不断刷新页面.
防止刷新的方法是javascript中有xmldocument(xml.load)来读取服务端*.xml文件(当然xml文件中要用.net读取服务器时间)
这样就不会刷新页面
 
<script language=&quot;javascript&quot;
type=&quot;text/javascript&quot;>
var today = new Date(&quot;<%=DateTime.Now.ToString(&quot;MM/dd/yyyy HH:mm:ss&quot;)%>&quot;);
function GetNow()
{
today.setSeconds(today.getSeconds() + 1);
do
cument.getElementById(&quot;curtime&quot;).innerText =&quot;今天是 &quot;
+ today.toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());
}
window.setInterval('GetNow()',1000);
</script>
 
后退
顶部