日期:2014-05-18  浏览次数:20438 次

asp.net页面里面怎么用js显示年月日?
如题

-------------------------------
  上午或下午好 |
  今天是x年x月x日 |
  星期x |  
  |
-------------------------------
我想在页面用js写

解决问题立即给分



------解决方案--------------------
function dispdate(){
var now=new Date(); 
var dd=now.getDate(),mt=now.getMonth()+1,yy=y2k(now.getYear()),weekVal=now.getDay(); 
if(weekVal==0) msg1="星期日"; 
else if(weekVal==1)msg1="星期一"; 
else if(weekVal==2)msg1="星期二"; 
else if(weekVal==3)msg1="星期三"; 
else if(weekVal==4)msg1="星期四"; 
else if(weekVal==5)msg1="星期五"; 
else if(weekVal==6)msg1="星期六"; 
var cl = '<font color="#ff0000" STYLE="font-size:9pt;">'+yy+"年"+mt+"月"+dd+"日 "+msg1+'</font>';
document.write(cl);
}
------解决方案--------------------
JScript code

       var year = new Date().getFullYear();
       var month = new Date().getMonth()+1;
       var day = new Date().getDay();
       var hour = new Date().getHours();
       var date = new Date().getDate();
       switch(day)
       {
            case 0:
                day="日";
                break;
            case 1:
                day="一";
                break;
            case 2:
                day="二";
                break;
            case 3:
                day="三";
                break;
            case 4:
                day="四";
                break;
            case 5:
                day="五";
                break;
            case 6:
                day="六";
                break;
       }
       var greetings = "";
       if(hour>=6 && hour <=12)
            greetings += "早上好";
        else if(hour >12 && hour <=19)
            greetings += "下午好";
       greetings += "<br>今天是" + year+ "年"+month+"月"+date+"日";
       greetings+="<br>星期"+day;
       document.write(greetings);

------解决方案--------------------
JScript code

<script language="Javascript"> 
  today=new Date(); 
  function date(){ 
  this.length=date.arguments.length 
  for(var i=0;i<this.length;i++) 
  this[i+1]=date.arguments } 
  var d=new date("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); 
  document.write( 
  "<font color=##000000 style='font-size:9pt;font-family: 宋体'> ", 
  today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日", 
  d[today.getDay()+1],"</font>" ); 
  </script>