<%
'Option Explicit
'**********************************************
' Class name: ChinaDay
'Purpose:
' Calculate the lunar calendar stems and branches of the date and the zodiac sign of the year based on the entered date
' Usage:
'The first parameter is the input parameter. If not filled in, it defaults to the current day.
'Only calculate dates after 1921-2-8
' ##------------------------------------------------##
'Dim objChinaDay
' Dim sDay, sWeekDay, sChinaDay, sChinaYear,sChinaAni
' Set objChinaDay = New ChinaDay
' Call objChinaDay.Action("",sDay,sWeekDay,sChinaYear,sChinaDay,sChinaAni)
' Response.Write sDay&"<BR>"
' Response.Write sWeekDay&"<BR>"
' Response.Write sChinaYear&"<BR>"
' Response.Write sChinaDay&"<BR>"
' Response.Write sChinaAni&"<BR>"
' ##------------------------------------------------##
' Modify By:Babyt(Artest)
'Mail: [email protected]
'Welcome To:
' http://blog.csdn.net/babyt/
' http://www.facesun.cn
' Created At: 2005-2-20
' Copyright: This code is not original and was collected in 2001. The original author is unknown.
'License:Free
'************************************************ ****
ClassChinaDay
Dim arrWeekName(7), MonthAdd(11), NongliData(99)
Dim arrTianGan(9), arrDiZhi(11), arrShuXiang(11), arrDayName(30), arrMonName(12)
Dim curTime, curYear, curMonth, curDay, curWeekday
Dim i, m, n, k, isEnd, bit, TheDate
'Initialize data
SubClass_Initialize()
'------------------------------------------------ --
'Define display string
'Week name
arrWeekName(0) = "*"
arrWeekName(1) = "Sunday"
arrWeekName(2) = "Monday"
arrWeekName(3) = "Tuesday"
arrWeekName(4) = "Wednesday"
arrWeekName(5) = "Thursday"
arrWeekName(6) = "Friday"
arrWeekName(7) = "Saturday"
'Heavenly stem name
arrTianGan(0) = "A"
arrTianGan(1) = "B"
arrTianGan(2) = "C"
arrTianGan(3) = "丁"
arrTianGan(4) = "五"
arrTianGan(5) = "自"
arrTianGan(6) = "庚"
arrTianGan(7) = "Xin"
arrTianGan(8) = "嬣"
arrTianGan(9) = "癸"
'Earthly branch name
arrDiZhi(0) = "子"
arrDiZhi(1) = "ugly"
arrDiZhi(2) = "Yin"
arrDiZhi(3) = "卯"
arrDiZhi(4) = "陈"
arrDiZhi(5) = "巳"
arrDiZhi(6) = "afternoon"
arrDiZhi(7) = "Not"
arrDiZhi(8) = "Shen"
arrDiZhi(9) = "You"
arrDiZhi(10) = "戌"
arrDiZhi(11) = "海"
'Zodiac name
arrShuXiang(0) = "rat"
arrShuXiang(1) = "Cow"
arrShuXiang(2) = "Tiger"
arrShuXiang(3) = "Rabbit"
arrShuXiang(4) = "龙"
arrShuXiang(5) = "Snake"
arrShuXiang(6) = "horse"
arrShuXiang(7) = "Sheep"
arrShuXiang(8) = "Monkey"
arrShuXiang(9) = "Chicken"
arrShuXiang(10) = "dog"
arrShuXiang(11) = "Pig"
'Lunar calendar date name
arrDayName(0) = "*"
arrDayName(1) = "First day of junior high school"
arrDayName(2) = "Second day of junior high school"
arrDayName(3) = "The third day of junior high school"
arrDayName(4) = "Fourth Day"
arrDayName(5) = "The fifth day of the lunar month"
arrDayName(6) = "The sixth day of the lunar month"
arrDayName(7) = "Seventh Day"
arrDayName(8) = "The eighth day of the lunar month"
arrDayName(9) = "Ninth day of the lunar month"
arrDayName(10) = "The tenth day of the lunar month"
arrDayName(11) = "Eleven"
arrDayName(12) = "Twelve"
arrDayName(13) = "Thirteen"
arrDayName(14) = "Fourteen"
arrDayName(15) = "Fifteen"
arrDayName(16) = "Sixteen"
arrDayName(17) = "Seventeen"
arrDayName(18) = "Eighteen"
arrDayName(19) = "Nineteen"
arrDayName(20) = "Twenty"
arrDayName(21) = "Twenty-one"
arrDayName(22) = "Twenty-Two"
arrDayName(23) = "Twenty-three"
arrDayName(24) = "Twenty-four"
arrDayName(25) = "Twenty-five"
arrDayName(26) = "Twenty-six"
arrDayName(27) = "Twenty-seven"
arrDayName(28) = "Twenty-eight"
arrDayName(29) = "Twenty-nine"
arrDayName(30) = "Thirty"
'Lunar month name
arrMonName(0) = "*"
arrMonName(1) = "Positive"
arrMonName(2) = "二"
arrMonName(3) = "三"
arrMonName(4) = "four"
arrMonName(5) = "五"
arrMonName(6) = "六"
arrMonName(7) = "seven"
arrMonName(8) = "eight"
arrMonName(9) = "九"
arrMonName(10) = "十"
arrMonName(11) = "Eleven"
arrMonName(12) = "Ra"
'------------------------------------------------ --------
'Tolerance data definition
'The number of days in front of each month in the Gregorian calendar
MonthAdd(0) = 0
MonthAdd(1) = 31
MonthAdd(2) = 59
MonthAdd(3) = 90
MonthAdd(4) = 120
MonthAdd(5) = 151
MonthAdd(6) = 181
MonthAdd(7) = 212
MonthAdd(8) = 243
MonthAdd(9) = 273
MonthAdd(10) = 304
MonthAdd(11) = 334
'Lunar calendar data
NongliData(0) = 2635
NongliData(1) = 333387
NongliData(2) = 1701
NongliData(3) = 1748
NongliData(4) = 267701
NongliData(5) = 694
NongliData(6) = 2391
NongliData(7) = 133423
NongliData(8) = 1175
NongliData(9) = 396438
NongliData(10) = 3402
NongliData(11) = 3749
NongliData(12) = 331177
NongliData(13) = 1453
NongliData(14) = 694
NongliData(15) = 201326
NongliData(16) = 2350
NongliData(17) = 465197
NongliData(18) = 3221
NongliData(19) = 3402
NongliData(20) = 400202
NongliData(21) = 2901
NongliData(22) = 1386
NongliData(23) = 267611
NongliData(24) = 605
NongliData(25) = 2349
NongliData(26) = 137515
NongliData(27) = 2709
NongliData(28) = 464533
NongliData(29) = 1738
NongliData(30) = 2901
NongliData(31) = 330421
NongliData(32) = 1242
NongliData(33) = 2651
NongliData(34) = 199255
NongliData(35) = 1323
NongliData(36) = 529706
NongliData(37) = 3733
NongliData(38) = 1706
NongliData(39) = 398762
NongliData(40) = 2741
NongliData(41) = 1206
NongliData(42) = 267438
NongliData(43) = 2647
NongliData(44) = 1318
NongliData(45) = 204070
NongliData(46) = 3477
NongliData(47) = 461653
NongliData(48) = 1386
NongliData(49) = 2413
NongliData(50) = 330077
NongliData(51) = 1197
NongliData(52) = 2637
NongliData(53) = 268877
NongliData(54) = 3365
NongliData(55) = 531109
NongliData(56) = 2900
NongliData(57) = 2922
NongliData(58) = 398042
NongliData(59) = 2395
NongliData(60) = 1179
NongliData(61) = 267415
NongliData(62) = 2635
NongliData(63) = 661067
NongliData(64) = 1701
NongliData(65) = 1748
NongliData(66) = 398772
NongliData(67) = 2742
NongliData(68) = 2391
NongliData(69) = 330031
NongliData(70) = 1175
NongliData(71) = 1611
NongliData(72) = 200010
NongliData(73) = 3749
NongliData(74) = 527717
NongliData(75) = 1452
NongliData(76) = 2742
NongliData(77) = 332397
NongliData(78) = 2350
NongliData(79) = 3222
NongliData(80) = 268949
NongliData(81) = 3402
NongliData(82) = 3493
NongliData(83) = 133973
NongliData(84) = 1386
NongliData(85) = 464219
NongliData(86) = 605
NongliData(87) = 2349
NongliData(88) = 334123
NongliData(89) = 2709
NongliData(90) = 2890
NongliData(91) = 267946
NongliData(92) = 2773
NongliData(93) = 592565
NongliData(94) = 1210
NongliData(95) = 2651
NongliData(96) = 395863
NongliData(97) = 1323
NongliData(98) = 2707
NongliData(99) = 265877
End Sub
'############################################### ###########
'Main method Action
' inDay Enter the date, if not entered, it defaults to the current date
'sDay Chinese format date
' sWeekDay Day of the week
' sChinaYear Lunar New Year
' sChinaDay lunar day
' sChinaAni zodiac sign
'############################################### ###########
Public Function Action(inDay,sDay,sWeekDay,sChinaYear,sChinaDay,sChinaAni)
'Convert the date to be converted
If inDay="" Or Not IsDate(inDay) Then
'Get the current system time
curTime = Now()
Else
curTime = CDate(inDay)
End If
If Datediff("d",curTime,Cdate("1921-2-8"))>0 Then
Exit Function
End If
'Generate the current Gregorian calendar year, month, and day ==> sDay
curYear = Year(curTime)
curMonth = Month(curTime)
curDay = Day(curTime)
sDay = curYear&"year"
If (curMonth < 10) Then
sDay = sDay&"0"&curMonth&"month"
Else
sDay = sDay&curMonth&"month"
End If
If (curDay < 10) Then
sDay = sDay&"0"&curDay&"日"
Else
sDay = sDay&curDay&"日"
End If
'Generate the current Gregorian calendar week ==> sWeekDay
curWeekday = Weekday(curTime)
sWeekDay = arrWeekName(curWeekday)
'Calculate the number of days to the initial time of February 8, 1921: 1921-2-8 (the first day of the first lunar month)
TheDate = (curYear - 1921) * 365 + Int((curYear - 1921) / 4) + curDay + MonthAdd(curMonth - 1) - 38
If ((curYear Mod 4) = 0 AND curMonth > 2) Then
TheDate = TheDate + 1
End If
'Calculate the celestial stems, earthly branches, months and days of the lunar calendar
isEnd = 0
m = 0
'---------------------------------------------
Do
If (NongliData(m) < 4095) Then
k=11
Else
k = 12
End if
n = k
'---------------------------------------------
Do
If (n < 0) Then
Exit Do
End If
'Get the value of the nth binary digit of NongliData(m)
bit = NongliData(m)
For i = 1 To n Step 1
bit = Int(bit / 2)
Next
bit = bit Mod 2
If (TheDate <= 29 + bit) Then
isEnd = 1
Exit Do
End If
TheDate = TheDate - 29 - bit
n=n-1
Loop
'---------------------------------------------
If (isEnd = 1) Then
Exit Do
End If
m = m + 1
Loop
'---------------------------------------------
curYear = 1921 + m
curMonth = k - n + 1
curDay = TheDate
If (k = 12) Then
If (curMonth = (Int(NongliData(m) / 65536) + 1)) Then
curMonth = 1 - curMonth
ElseIf (curMonth > (Int(NongliData(m) / 65536) + 1)) Then
curMonth = curMonth - 1
End if
End If
'Generate lunar calendar celestial stems and earthly branches ==> sChinaYear
sChinaYear = "Lunar Calendar"&arrTianGan(((curYear - 4) Mod 60) Mod 10)&arrDiZhi(((curYear - 4) Mod 60) Mod 12)&"Year"
'Generate zodiac == > sChinaAni
sChinaAni = arrShuXiang(((curYear - 4) Mod 60) Mod 12)
'Generate lunar month and day ==> NongliDayStr
If (curMonth < 1) Then
sChinaDay = "Leap"&arrMonName(-1 * curMonth)
Else
sChinaDay = arrMonName(curMonth)
End If
sChinaDay = sChinaDay&"month"
sChinaDay = sChinaDay & arrDayName(curDay)
End Function
End Class
%>