javascript 當前日期轉化為中文的實現代碼

來源:互聯網
上載者:User

複製代碼 代碼如下:<script type="text/javascript">
function initArray(){
this.length=initArray.arguments.length;
for(var i=0;i<this.length;i++){
this[i]=initArray.arguments[i];
}
}
  var strA="";
  function TimeList()
  {
   var i=0;
   var str=new Array("零","壹","貳","三","肆","伍","陸","妻","捌","玖");
   var str2=new Array("一","二","三","四","五","六","七","八","九","十");
   var str3=new Array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
   var time=new Date();
   var year=new initArray(time.getFullYear().toString().split("")[0],time.getFullYear().toString().split("")[1],time.getFullYear().toString().split("")[2],time.getFullYear().toString().split("")[3]);
   //var year=eval(time.getFullYear().toString());
   var month;
   if(time.getMonth().toString().length>1)
   {
   month=new initArray(time.getMonth().toString().split("")[0],time.getMonth().toString().split("")[1]);
   }
   else
   {
   month=new initArray(time.getMonth().toString().split("")[0]);
   }
  
  
  
   var len=year.length;
   for(i=0;i<4;i++) //年
   {
   var k=parseInt(year[i]);
 
   strA+=str[k];
   }
   strA+="年";
   var j=0;
   var strB="";
   if(month.length>1)
   {
   strB+=str2[9];
   strB+=str2[parseInt(time.getMonth().toString().split("")[1])];
   }
   else
   {
   strB+=str2[parseInt(time.getMonth().toString().split("")[0])];
   }
   strA+=strB;
   strA+="月";
   var strD="";
   if(time.getDate().toString().length>1)
   {
   if(parseInt(time.getDate().toString().split("")[0])>1)
   {
   strD+=str2[parseInt(time.getDate().toString().split("")[0])-1];
   strD+=str2[9];
   if(parseInt(time.getDate().toString().split("")[1])>0)
   {
   strD+=str2[parseInt(time.getDate().toString().split("")[1])-1];
   }
   else
   {
   strD+="";
   }
   }
   else
   {
   if(parseInt(time.getDate().toString().split("")[1])==0)
   {
   strD+="初";
   strD+=str2[9];
   }
   else
   {
   strD+=str2[9];
   strD+=str2[parseInt(time.getDate().toString().split("")[1])-1];
   }
  
   }
   }
   else
   {
   strD+="初";
   strD+=str2[parseInt(time.getDate().toString().split("")[0])-1];
   }
   strA+=strD;
   strA+=" ";
  
   var sta=time.getDay();
   strA+=str3[sta];
   document.getElementById("Text1").value=strA;
   document.getElementById("TextBox1").innerText=strA;
   document.all.Label1.innerText=strA;
   document.form1.TextBox2.innerText=strA;
  
  }
</script>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.