Javascript to get the lunar date code of the current date

Source: Internet
Author: User

Javascript to get the lunar date code of the current date

JavaScript code

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

/* Set the lunar date */

Var CalendarData = new Array (100 );

Var madd = new Array (12 );

Var numString = "February 5, 1234, 80 or 90 ";

Var monString = "June 2345, 80 or 90 Winter ";

Var cYear, cMonth, cDay, TheDate;

// The lunar calendar month can only be 29 or 30 days. 12 (or 13) binary digits are used for a year. from high to low, 1 indicates 30 days. Otherwise, 29 days are used.

CalendarData = new Array (0xA4B, 0x5164B, 0x6A5, 0x6D4, 0x0000b5, 0x2B6, 0 × 957, 0x2092F, 0 × 497, 0x60C96, 0xD4A, 0xEA5, 0x50DA9, 0x5AD,

0x2B6, 0x3126E, 0x92E, 0x7192D, 0xC95, 0xD4A, 0x61B4A, 0xB55, 0x56A, 0x00005b, 0x25D, 0x92D, 0x2192B, 0xA95, 0 × 71695, 0x6CA,

0xB55, fingerprint, 0x4DA, 0xA5B, 0x30A57, 0x52B, 0x8152A, 0xE95, 0x6AA, 0x615AA, 0xAB5, 0x4B6, expires, 0xA57, 0 × 526, 0x31D26, 0xD95,

Primary, 0x56A, 0x96D, 0x5095D, 0x4AD, 0xA4D, 0x41A4D, 0xD25, 0x81AA5, 0xB54, 0xB6A, primary, 0x95B, 0x49B, 0 × 41497, 0xA4B, 0xA164B,

0x6A5, 0x6D4, 0x615B4, 0xAB6, 0 × 957, 0x5092F, 0 × 497, 0x64B, primary, 0xEA5, primary, 0x5AC, 0xAB6, 0x5126D, 0x92E, 0xC96, 0x41A95,

0xD4A, 0xDA5, 0x20B55, 0x56A, 0x7155B, 0x25D, 0x92D, 0x5192B, 0xA95, 0xB4A, 0x416AA, 0xAD5, 0x4BA, 0xA5B, 0x60A57, 0x52B,

0xA93, 0x40E95 );

Madd [0] = 0;

Madd [1] = 31;

Madd [2] = 59;

Madd [3] = 90;

Madd [4] = 120;

Madd [5] = 151;

Madd [6] = 181;

Madd [7] = 212;

Madd [8] = 243;

Madd [9] = 273;

Madd [10] = 304;

Madd [11] = 334;

Function GetBit (m, n ){

Return (m> 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 (tmp <1900 ){

Tmp+ = 1900;

}

Total = (tmp-1921) * 365 + Math. floor (tmp-1921)/4) + madd [TheDate. getMonth ()] + TheDate. getDate ()-38;

If (TheDate. getYear () % 4 = 0 & TheDate. getMonth ()> 1 ){

Total ++;

}

For (m = 0; m ++ ){

K = (CalendarData [m] <0 xfff )? 11: 12;

For (n = k; n> = 0; n --){

If (total <= 29 + GetBit (CalendarData [m], n )){

IsEnd = true; break;

}

Total = total-29-GetBit (CalendarData [m], n );

}

If (isEnd) break;

}

CYear = 1921 + m;

CMonth = k-n + 1;

CDay = total;

If (k = 12 ){

If (cMonth = Math. floor (CalendarData [m]/0x10000) + 1 ){

CMonth = 1-cMonth;

}

If (cMonth> Math. floor (CalendarData [m]/0x10000) + 1 ){

CMonth --;

}

}

}

Function GetcDateString (){

Var tmp = "";

If (cMonth <1 ){

Tmp + = "(bytes )";

Tmp + = monString. charAt (-cMonth-1 );

} Else {

Tmp + = monString. charAt (cMonth-1 );

}

Tmp + = "month ";

Tmp + = (cDay <11 )? "Chu" :( (cDay <20 )? "10" :( (cDay <30 )? "Identifier": "Thirty "));

If (cDay % 10! = 0 | cDay = 10 ){

Tmp + = numString. charAt (cDay-1) % 10 );

}

Return tmp;

}

Function GetLunarDay (solarYear, solarMonth, solarDay ){

// SolarYear = solarYear <1900? (1900 + solarYear): solarYear;

If (solarYear <1921 | solarYear> 2020 ){

Return "";

} Else {

SolarMonth = (parseInt (solarMonth)> 0 )? (SolarMonth-1): 11;

E2c (solarYear, solarMonth, solarDay );

Return GetcDateString ();

}

}

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 <100) yy = "19" + yy;

Function showCal (){

Var nongli = GetLunarDay (yy, mm, dd );

Return nongli;

}

/* Set end for the lunar calendar */

Call

The Code is as follows:


$ ('# Tianqi h5'). text (showCal ());


Effect:

 

September 11 is the lunar date of the day.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.