JavaScript code for Fully displaying the lunar calendar date _ time date
Last Update:2017-05-11
Source: Internet
Author: User
The following code is saved and called in js. Function RunGLNL (){
Var today = new Date ();
Var d = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ");
Var DDDD = (today. getYear () <100?
Today. getYear () + 1900: today. getYear () + "year" + (today. getMonth () + 1) + "month" + today. getDate () + "day ";
DDDD = DDDD + "" + d [today. getDay ()];
DDDD = DDDD + "" + (CnDateofDateStr (today ));
// DDDD = DDDD + "" + SolarTerm (today );
Document. write (DDDD );
}
Function DaysNumberofDate (DateGL ){
Return parseInt (Date. parse (DateGL)-Date. parse (DateGL. getYear () + "/1/1")/86400000) + 1;
}
Function CnDateofDate (DateGL ){
Var CnData = new Array (
0x16, 0x2a, 0xda, 0x00,0x83,0x49, 0xb6, 0x05, 0x0e, 0x64, 0xbb, 0x00,0x19, 0xb2, 0x5b, 0x00,
0x87, 0x6a, 0x57,0x04,0x12,0x75, 0x2b, 0x00, 0x1d, 0xb6, 0x95,0x00, 0x8a, 0xad, 0x55, 0x02,
0x55, 0xaa, 0 x, 0 x, 0x55, 0x6c, 0x07, 0x0d, 0xc9, 0 x, 0 x, 0 x, 0x64, 0xb7, 0x00,
0x86, 0xe4, 0xae, 0x05, 0x11, 0xea, 0x56, 0x00, 0x1b, 0x6d, 0x2a, 0x00,0x88, 0x5a, 0xaa, 0x04,
0x14, 0xad, 0x55, 0 x, 0x81, 0xaa, 0xd5, 0x09, 0x0b, 0x52, 0xea, 0 x, 0x16, 0xa9, 0x6d, 0x00,
0x84, 0xa9, 0x5d, 0x06, 0x0f, 0xd4, 0xae, 0x00, 0x1a, 0xea, 0x4d, 0x00,0x87, 0xba, 0x55, 0x04
);
Var CnMonth = new Array ();
Var CnMonthDays = new Array ();
Var CnBeginDay;
Var LeapMonth;
Var Bytes = new Array ();
Var I;
Var CnMonthData;
Var DaysCount;
Var CnDaysCount;
Var ResultMonth;
Var ResultDay;
Var yyyy = DateGL. getYear ();
Var mm = DateGL. getMonth () + 1;
Var dd = DateGL. getDate ();
If (yyyy <100) yyyy + = 1900;
If (yyyy <1997) | (yyyy> 2020 )){
Return 0;
}
Bytes [0] = CnData [(yyyy-1997) * 4];
Bytes [1] = CnData [(yyyy-1997) * 4 + 1];
Bytes [2] = CnData [(yyyy-1997) * 4 + 2];
Bytes [3] = CnData [(yyyy-1997) * 4 + 3];
If (Bytes [0] & 0x80 )! = 0) {CnMonth [0] = 12 ;}
Else {CnMonth [0] = 11 ;}
CnBeginDay = (Bytes [0] & 0x7f );
CnMonthData = Bytes [1];
CnMonthData = CnMonthData <8;
CnMonthData = CnMonthData | Bytes [2];
LeapMonth = Bytes [3];
For (I = 15; I> = 0; I --){
CnMonthDays [15-I] = 29;
If (1 <I) & CnMonthData )! = 0 ){
CnMonthDays [15-I] ++ ;}
If (CnMonth [15-I] = LeapMonth ){
CnMonth [15-I + 1] =-LeapMonth ;}
Else {
If (CnMonth [15-I] <0) {CnMonth [15-I + 1] =-CnMonth [15-I] + 1 ;}
Else {CnMonth [15-I + 1] = CnMonth [15-I] + 1 ;}
If (CnMonth [15-I + 1]> 12) {CnMonth [15-I + 1] = 1 ;}
}
}
DaysCount = DaysNumberofDate (DateGL)-1;
If (DaysCount <= (CnMonthDays [0]-CnBeginDay )){
If (yyyy> 1901) & (CnDateofDate (new Date (yyyy-1) + "/12/31") <0 )){
ResultMonth =-CnMonth [0];}
Else {ResultMonth = CnMonth [0];}
ResultDay = CnBeginDay + DaysCount;
}
Else {
CnDaysCount = CnMonthDays [0]-CnBeginDay;
I = 1;
While (CnDaysCount <DaysCount) & (CnDaysCount + CnMonthDays [I] <DaysCount )){
CnDaysCount + = CnMonthDays [I];
I ++;
}
ResultMonth = CnMonth [I];
ResultDay = DaysCount-CnDaysCount;
}
If (ResultMonth> 0 ){
Return ResultMonth * 100 + ResultDay ;}
Else {return ResultMonth * 100-ResultDay ;}
}
Function CnYearofDate (DateGL ){
Var YYYY = DateGL. getYear ();
Var MM = DateGL. getMonth () + 1;
Var CnMM = parseInt (Math. abs (CnDateofDate (DateGL)/100 );
If (YYYY <100) YYYY + = 1900;
If (CnMM> MM) YYYY --;
YYYY-= 1864;
Return CnEra (YYYY) + "year ";
}
Function CnMonthofDate (DateGL ){
Var CnMonthStr = new Array ("zero", "positive", "two", "three", "four", "five", "Six", "Seven ", "8", "9", "10", "11", "La ");
Var Month;
Monthly = parseInt (CnDateofDate (DateGL)/100 );
If (Month <0) {return "months" + CnMonthStr [-Month] + "Month ";}
Else {return CnMonthStr [Month] + "Month ";}
}
Function CnDayofDate (DateGL ){
Var CnDayStr = new Array ("zero ",
"1st", "2nd", "3rd", "4th", "5th ",
"Sixth Day", "Seventh Day", "Eighth Day", "Ninth Day", "tenth day ",
"11", "12", "13", "14", "15 ",
"16", "17", "18", "19", "20 ",
"Category 1", "Category 2", "Category 3", "Category 4", "Category 5 ",
"Sixty-six", "Fifty-seven", "Fifty-eight", "fifty-nine", "Thirty ");
Var Day;
Day = (Math. abs (CnDateofDate (DateGL) %100;
Return CnDayStr [Day];
}
Function DaysNumberofMonth (DateGL ){
Var MM1 = DateGL. getYear ();
What is MM1 <100? MM1 + = 1900: MM1;
Var MM2 = MM1;
MM1 + = "/" + (DateGL. getMonth () + 1 );
MM2 + = "/" + (DateGL. getMonth () + 2 );
MM1 + = "/1 ";
MM2 + = "/1 ";
Return parseInt (Date. parse (MM2)-Date. parse (MM1)/86400000 );
}
Function CnEra (YYYY ){
Var Tiangan = new Array ("A", "B", "C", "ding", "E", "Ji", "Geng", "Xin ", "yellow", "yellow ");
// Var Dizhi = new Array ("sub (rat)", "ugly (COW)", "yin (TIGER)", "Mao (rabbit )", "Chen (Dragon)", "Si (snake )",
// "Wu (Horse)", "Wu (Goat)", "Shen (monkey)", "You (chicken)", "Yellow (DOG )", "Hai (pig )");
Var Dizhi = new Array ("sub", "ugly", "Yin", "Mao", "Chen", "Si", "Wu", "wei ", "shen", "you", "shen", "Hai ");
Return Tiangan [YYYY % 10] + Dizhi [YYYY % 12];
}
Function CnDateofDateStr (DateGL ){
If (CnMonthofDate (DateGL) = "") return "Please adjust your computer date! ";
Else return ":" + CnYearofDate (DateGL) + "" + CnMonthofDate (DateGL) + CnDayofDate (DateGL );
}
Function SolarTerm (DateGL ){
Var SolarTermStr = new Array (
"Xiao Han", "da Han", "Li Chun", "Rain", "stunned", "Spring Equinox ",
"Qingming", "Gu Yu", "lixia", "xiaoman", "Mango", "xia zhi ",
"Slight Heat", "great heat", "Autumn", "Summer heat", "White Dew", "Autumn Equinox ",
"Cold Dew", "frost", "Winter", "light snow", "heavy snow", "Winter Solstice ");
Var DifferenceInMonth = new Array (
20172060,5495, 1281180,1289445, 1299225,1310355,
1321560,1333035, 1342770,1350855, 1356420,1359045,
1358580,1355055, 1348695,1340040, 1329630,1318455,
1306935,1297380, 1286865,1277730, 4154550,4151556 );
Var DifferenceInYear = 31556926;
Var BeginTime = new Date (1901/1/1 );
BeginTime. setTime (947120460000 );
For (; DateGL. getYear () BeginTime. setTime (BeginTime. getTime ()-DifferenceInYear * 1000 );
}
For (; DateGL. getYear ()> BeginTime. getYear ();){
BeginTime. setTime (BeginTime. getTime () + DifferenceInYear * 1000 );
}
For (var M = 0; DateGL. getMonth ()> BeginTime. getMonth (); M ++ ){
BeginTime. setTime (BeginTime. getTime () + DifferenceInMonth [M] * 1000 );
}
If (DateGL. getDate ()> BeginTime. getDate ()){
BeginTime. setTime (BeginTime. getTime () + DifferenceInMonth [M] * 1000 );
M ++;
}
If (DateGL. getDate ()> BeginTime. getDate ()){
BeginTime. setTime (BeginTime. getTime () + DifferenceInMonth [M] * 1000 );
M = 23? M = 0: M ++;
}
Var JQ;
If (DateGL. getDate () = BeginTime. getDate ()){
JQ = "today is
"+ SolarTermStr [M] +" ";
}
Else if (DateGL. getDate () = BeginTime. getDate ()-1 ){
JQ = "Tomorrow is
"+ SolarTermStr [M] +" ";
}
Else if (DateGL. getDate () = BeginTime. getDate ()-2 ){
JQ = "The Day After Tomorrow is
"+ SolarTermStr [M] +" ";
}
Else {
JQ = ""
If (DateGL. getMonth () = BeginTime. getMonth ()){
JQ + = "this month ";
}
Else {
JQ + = "Next Month ";
}
JQ + = BeginTime. getDate () + "day" +"
"+ SolarTermStr [M] +" ";
}
Return JQ;
}
Function CAL ()
{}
RunGLNL ();