javascript 当前日期转化为中文的实现代码
作者:
有时候需要将当面的日期,转换成中文,这里是js的实现代码,需要的朋友可以参考下。
复制代码 代码如下:
<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>