欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

显示今天的日期js代码(阳历和农历)_javascript技巧

程序员文章站 2022-05-02 16:35:02
...
1.显示日期代码:

Js代码

/*获取当前日期*/ 
function getCurrentDateTime() { 
var d = new Date(); 
var year = d.getFullYear(); 
var month = d.getMonth() + 1; 
var date = d.getDate(); 
var week = d.getDay(); 
/*时分秒*/ 
/*var hours = d.getHours(); 
var minutes = d.getMinutes(); 
var seconds = d.getSeconds(); 
var ms = d.getMilliseconds();*/ 
var curDateTime = year; 
if (month > 9) 
curDateTime = curDateTime + "年" + month; 
else 
curDateTime = curDateTime + "年0" + month; 
if (date > 9) 
curDateTime = curDateTime + "月" + date + "日"; 
else 
curDateTime = curDateTime + "月0" + date + "日"; 
/*if (hours > 9) 
curDateTime = curDateTime + " " + hours; 
else 
curDateTime = curDateTime + " 0" + hours; 
if (minutes > 9) 
curDateTime = curDateTime + ":" + minutes; 
else 
curDateTime = curDateTime + ":0" + minutes; 
if (seconds > 9) 
curDateTime = curDateTime + ":" + seconds; 
else 
curDateTime = curDateTime + ":0" + seconds;*/ 
var weekday = ""; 
if (week == 0) 
weekday = "星期日"; 
else if (week == 1) 
weekday = "星期一"; 
else if (week == 2) 
weekday = "星期二"; 
else if (week == 3) 
weekday = "星期三"; 
else if (week == 4) 
weekday = "星期四"; 
else if (week == 5) 
weekday = "星期五"; 
else if (week == 6) 
weekday = "星期六"; 
curDateTime = curDateTime + " " + weekday; 
return curDateTime; 
}

2.显示农历代码:

Js代码

/*获取当前农历*/ 
function showCal(){ 
var D=new Date(); 
var yy=D.getFullYear(); 
var mm=D.getMonth()+1; 
var dd=D.getDate(); 
var ww=D.getDay(); 
var ss=parseInt(D.getTime() / 1000); 
if (yy>n)&1; 
} 
//农历转换 
function e2c(){ 
TheDate= (arguments.length!=3) ? new Date() : new Date(arguments[0],arguments[1],arguments[2]); 
var total,m,n,k; 
var isEnd=false; 
var tmp=TheDate.getYear(); 
if(tmp1) { 
total++; 
} 
for(m=0;;m++){ 
k=(CalendarData[m]=0;n--){ 
if(totalMath.floor(CalendarData[m]/0x10000)+1){ 
cMonth--; 
} 
} 
} 

function GetcDateString(){ 
var tmp=""; 
/*显示农历年:( 如:甲午(马)年 )*/ 
/*tmp+=tgString.charAt((cYear-4)%10); 
tmp+=dzString.charAt((cYear-4)%12); 
tmp+="("; 
tmp+=sx.charAt((cYear-4)%12); 
tmp+=")年 ";*/ 
if(cMonth2020){ 
return ""; 
}else{ 
solarMonth = (parseInt(solarMonth)>0) ? (solarMonth-1) : 11; 
e2c(solarYear,solarMonth,solarDay); 
return GetcDateString(); 
} 
}

3.显示:

Js代码

$(function(){ 
var date = getCurrentDateTime(); 
var calendar = showCal(); 
$("#currentDate").text("今天是: " + date + "农历:" + calendar); 
});

显示今天的日期js代码(阳历和农历)_javascript技巧

相关标签: 日期 农历