Board logo

标题: [转贴] 阳历转农历.vbs [打印本页]

作者: fastslz    时间: 2011-7-19 10:11     标题: 阳历转农历.vbs

  1. Dim NLDate
  2. aDate=Inputbox("请输入日期:","阳历转农历",Date)
  3. NL(aDate)
  4. msgbox NLDate
  5. Function NL(DateStr)
  6. '获取当前系统时间powered by 25175.net
  7. curTime = DateStr
  8. Dim WeekName(7), MonthAdd(11), NongliData(99), TianGan(9), DiZhi(11), ShuXiang(11), DayName(30), MonName(12)
  9. '星期名
  10. WeekName(0) = " * "
  11. WeekName(1) = "星期日"
  12. WeekName(2) = "星期一"
  13. WeekName(3) = "星期二"
  14. WeekName(4) = "星期三"
  15. WeekName(5) = "星期四"
  16. WeekName(6) = "星期五"
  17. WeekName(7) = "星期六"
  18. '天干名称
  19. TianGan(0) = "甲"
  20. TianGan(1) = "乙"
  21. TianGan(2) = "丙"
  22. TianGan(3) = "丁"
  23. TianGan(4) = "戊"
  24. TianGan(5) = "己"
  25. TianGan(6) = "庚"
  26. TianGan(7) = "辛"
  27. TianGan(8) = "壬"
  28. TianGan(9) = "癸"
  29. '地支名称
  30. DiZhi(0) = "子"
  31. DiZhi(1) = "丑"
  32. DiZhi(2) = "寅"
  33. DiZhi(3) = "卯"
  34. DiZhi(4) = "辰"
  35. DiZhi(5) = "巳"
  36. DiZhi(6) = "午"
  37. DiZhi(7) = "未"
  38. DiZhi(8) = "申"
  39. DiZhi(9) = "酉"
  40. DiZhi(10) = "戌"
  41. DiZhi(11) = "亥"
  42. '属相名称
  43. ShuXiang(0) = "鼠"
  44. ShuXiang(1) = "牛"
  45. ShuXiang(2) = "虎"
  46. ShuXiang(3) = "兔"
  47. ShuXiang(4) = "龙"
  48. ShuXiang(5) = "蛇"
  49. ShuXiang(6) = "马"
  50. ShuXiang(7) = "羊"
  51. ShuXiang(8) = "猴"
  52. ShuXiang(9) = "鸡"
  53. ShuXiang(10) = "狗"
  54. ShuXiang(11) = "猪"
  55. '农历日期名
  56. DayName(0) = "*"
  57. DayName(1) = "初一"
  58. DayName(2) = "初二"
  59. DayName(3) = "初三"
  60. DayName(4) = "初四"
  61. DayName(5) = "初五"
  62. DayName(6) = "初六"
  63. DayName(7) = "初七"
  64. DayName(8) = "初八"
  65. DayName(9) = "初九"
  66. DayName(10) = "初十"
  67. DayName(11) = "十一"
  68. DayName(12) = "十二"
  69. DayName(13) = "十三"
  70. DayName(14) = "十四"
  71. DayName(15) = "十五"
  72. DayName(16) = "十六"
  73. DayName(17) = "十七"
  74. DayName(18) = "十八"
  75. DayName(19) = "十九"
  76. DayName(20) = "二十"
  77. DayName(21) = "廿一"
  78. DayName(22) = "廿二"
  79. DayName(23) = "廿三"
  80. DayName(24) = "廿四"
  81. DayName(25) = "廿五"
  82. DayName(26) = "廿六"
  83. DayName(27) = "廿七"
  84. DayName(28) = "廿八"
  85. DayName(29) = "廿九"
  86. DayName(30) = "三十"
  87. '农历月份名
  88. MonName(0) = "*"
  89. MonName(1) = "正"
  90. MonName(2) = "二"
  91. MonName(3) = "三"
  92. MonName(4) = "四"
  93. MonName(5) = "五"
  94. MonName(6) = "六"
  95. MonName(7) = "七"
  96. MonName(8) = "八"
  97. MonName(9) = "九"
  98. MonName(10) = "十"
  99. MonName(11) = "十一"
  100. MonName(12) = "腊"
  101. '公历每月前面的天数
  102. MonthAdd(0) = 0
  103. MonthAdd(1) = 31
  104. MonthAdd(2) = 59
  105. MonthAdd(3) = 90
  106. MonthAdd(4) = 120
  107. MonthAdd(5) = 151
  108. MonthAdd(6) = 181
  109. MonthAdd(7) = 212
  110. MonthAdd(8) = 243
  111. MonthAdd(9) = 273
  112. MonthAdd(10) = 304
  113. MonthAdd(11) = 334
  114. '农历数据
  115. NongliData(0) = 2635
  116. NongliData(1) = 333387
  117. NongliData(2) = 1701
  118. NongliData(3) = 1748
  119. NongliData(4) = 267701
  120. NongliData(5) = 694
  121. NongliData(6) = 2391
  122. NongliData(7) = 133423
  123. NongliData(8) = 1175
  124. NongliData(9) = 396438
  125. NongliData(10) = 3402
  126. NongliData(11) = 3749
  127. NongliData(12) = 331177
  128. NongliData(13) = 1453
  129. NongliData(14) = 694
  130. NongliData(15) = 201326
  131. NongliData(16) = 2350
  132. NongliData(17) = 465197
  133. NongliData(18) = 3221
  134. NongliData(19) = 3402
  135. NongliData(20) = 400202
  136. NongliData(21) = 2901
  137. NongliData(22) = 1386
  138. NongliData(23) = 267611
  139. NongliData(24) = 605
  140. NongliData(25) = 2349
  141. NongliData(26) = 137515
  142. NongliData(27) = 2709
  143. NongliData(28) = 464533
  144. NongliData(29) = 1738
  145. NongliData(30) = 2901
  146. NongliData(31) = 330421
  147. NongliData(32) = 1242
  148. NongliData(33) = 2651
  149. NongliData(34) = 199255
  150. NongliData(35) = 1323
  151. NongliData(36) = 529706
  152. NongliData(37) = 3733
  153. NongliData(38) = 1706
  154. NongliData(39) = 398762
  155. NongliData(40) = 2741
  156. NongliData(41) = 1206
  157. NongliData(42) = 267438
  158. NongliData(43) = 2647
  159. NongliData(44) = 1318
  160. NongliData(45) = 204070
  161. NongliData(46) = 3477
  162. NongliData(47) = 461653
  163. NongliData(48) = 1386
  164. NongliData(49) = 2413
  165. NongliData(50) = 330077
  166. NongliData(51) = 1197
  167. NongliData(52) = 2637
  168. NongliData(53) = 268877
  169. NongliData(54) = 3365
  170. NongliData(55) = 531109
  171. NongliData(56) = 2900
  172. NongliData(57) = 2922
  173. NongliData(58) = 398042
  174. NongliData(59) = 2395
  175. NongliData(60) = 1179
  176. NongliData(61) = 267415
  177. NongliData(62) = 2635
  178. NongliData(63) = 661067
  179. NongliData(64) = 1701
  180. NongliData(65) = 1748
  181. NongliData(66) = 398772
  182. NongliData(67) = 2742
  183. NongliData(68) = 2391
  184. NongliData(69) = 330031
  185. NongliData(70) = 1175
  186. NongliData(71) = 1611
  187. NongliData(72) = 200010
  188. NongliData(73) = 3749
  189. NongliData(74) = 527717
  190. NongliData(75) = 1452
  191. NongliData(76) = 2742
  192. NongliData(77) = 332397
  193. NongliData(78) = 2350
  194. NongliData(79) = 3222
  195. NongliData(80) = 268949
  196. NongliData(81) = 3402
  197. NongliData(82) = 3493
  198. NongliData(83) = 133973
  199. NongliData(84) = 1386
  200. NongliData(85) = 464219
  201. NongliData(86) = 605
  202. NongliData(87) = 2349
  203. NongliData(88) = 334123
  204. NongliData(89) = 2709
  205. NongliData(90) = 2890
  206. NongliData(91) = 267946
  207. NongliData(92) = 2773
  208. NongliData(93) = 592565
  209. NongliData(94) = 1210
  210. NongliData(95) = 2651
  211. NongliData(96) = 395863
  212. NongliData(97) = 1323
  213. NongliData(98) = 2707
  214. NongliData(99) = 265877
  215. '生成当前公历年、月、日 ==> GongliStr
  216. curYear = Year(curTime)
  217. curMonth = Month(curTime)
  218. curDay = Day(curTime)
  219. GongliStr = curYear & "年"
  220. If (curMonth < 10) Then
  221.     GongliStr = GongliStr & "0" & curMonth & "月"
  222. Else
  223.     GongliStr = GongliStr & curMonth & "月"
  224. End If
  225. If (curDay < 10) Then
  226.     GongliStr = GongliStr & "0" & curDay & "日"
  227. Else
  228.     GongliStr = GongliStr & curDay & "日"
  229. End If
  230. '生成当前公历星期 ==> WeekdayStr
  231. curWeekday = Weekday(curTime)
  232. WeekdayStr = WeekName(curWeekday)
  233. '计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)
  234. TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38
  235. If ((curYear Mod 4) = 0 And curMonth > 2) Then
  236.     TheDate = TheDate + 1
  237. End If
  238. '计算农历天干、地支、月、日
  239. isEnd = 0
  240. m = 0
  241. Do
  242.     If (NongliData(m) < 4095) Then
  243.         k = 11
  244.     Else
  245.         k = 12
  246.     End If
  247.     n = k
  248.     Do
  249.         If (n < 0) Then
  250.             Exit Do
  251.         End If
  252.     '获取NongliData(m)的第n个二进制位的值
  253.     bit = NongliData(m)
  254.     For i = 1 To n Step 1
  255.         bit = Int(bit / 2)
  256.     Next
  257.     bit = bit Mod 2
  258.     If (TheDate <= 29 + bit) Then
  259.         isEnd = 1
  260.         Exit Do
  261.     End If
  262.     TheDate = TheDate - 29 - bit
  263.     n = n - 1
  264.   Loop
  265.   If (isEnd = 1) Then
  266.       Exit Do
  267.   End If
  268.   m = m + 1
  269. Loop
  270. curYear = 1921 + m
  271. curMonth = k - n + 1
  272. curDay = TheDate
  273. If (k = 12) Then
  274.     If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
  275.         curMonth = 1 - curMonth
  276.     ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
  277.         curMonth = curMonth - 1
  278.     End If
  279. End If
  280. '生成农历天干、地支、属相 ==> NongliStr
  281. NongliStr = "农历" & TianGan(((curYear - 4) Mod 60) Mod 10) & DiZhi(((curYear - 4) Mod 60) Mod 12) & "年"
  282. NongliStr = NongliStr & "(" & ShuXiang(((curYear - 4) Mod 60) Mod 12) & ")"
  283. '生成农历月、日 ==> NongliDayStr
  284. If (curMonth < 1) Then
  285.     NongliDayStr = "闰" & MonName(-1 * curMonth)
  286. Else
  287.     NongliDayStr = MonName(curMonth)
  288. End If
  289. NongliDayStr = NongliDayStr & "月"
  290. NongliDayStr = NongliDayStr & DayName(curDay)
  291. NLDate = NongliStr & NongliDayStr
  292. End Function
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2