请教Pcbar关于公历转农历一些函数 [感谢Pcbar]
下面是你整理的一个公历转换农历的函数我看到里面有节日,可是尝试调用发现不成功
请Pbar指点一下如何调用到里面设置的公历和农历的节日
非常感谢;关于公历转农历一些函数
;pcbar 收集整理 2008.05
#include <GUIConstants.au3>
#include <Constants.au3>
#include <date.au3>
#include <WindowsConstants.au3>
Global $gLunarMonthDay = _
[0X4ae0, 0Xa570, 0X5268, 0Xd260, 0Xd950, 0X6aa8, 0X56a0, 0X9ad0, 0X4ae8, 0X4ae0, _
0Xa4d8, 0Xa4d0, 0Xd250, 0Xd548, 0Xb550, 0X56a0, 0X96d0, 0X95b0, 0X49b8, 0X49b0, _
0Xa4b0, 0Xb258, 0X6a50, 0X6d40, 0Xada8, 0X2b60, 0X9570, 0X4978, 0X4970, 0X64b0, _
0Xd4a0, 0Xea50, 0X6d48, 0X5ad0, 0X2b60, 0X9370, 0X92e0, 0Xc968, 0Xc950, 0Xd4a0, _
0Xda50, 0Xb550, 0X56a0, 0Xaad8, 0X25d0, 0X92d0, 0Xc958, 0Xa950, 0Xb4a8, 0X6ca0, _
0Xb550, 0X55a8, 0X4da0, 0Xa5b0, 0X52b8, 0X52b0, 0Xa950, 0Xe950, 0X6aa0, 0Xad50, _
0Xab50, 0X4b60, 0Xa570, 0Xa570, 0X5260, 0Xe930, 0Xd950, 0X5aa8, 0X56a0, 0X96d0, _
0X4ae8, 0X4ad0, 0Xa4d0, 0Xd268, 0Xd250, 0Xd528, 0Xb540, 0Xb6a0, 0X96d0, 0X95b0, _
0X49b0, 0Xa4b8, 0Xa4b0, 0Xb258, 0X6a50, 0X6d40, 0Xada0, 0Xab60, 0X9370, 0X4978, _
0X4970, 0X64b0, 0X6a50, 0Xea50, 0X6b28, 0X5ac0, 0Xab60, 0X9368, 0X92e0, 0Xc960, _
0Xd4a8, 0Xd4a0, 0Xda50, 0X5aa8, 0X56a0, 0Xaad8, 0X25d0, 0X92d0, 0Xc958, 0Xa950, _
0Xb4a0, 0Xb550, 0Xb550, 0X55a8, 0X4ba0, 0Xa5b0, 0X52b8, 0X52b0, 0Xa930, 0X74a8, _
0X6aa0, 0Xad50, 0X4da8, 0X4b60, 0X9570, 0Xa4e0, 0Xd260, 0Xe930, 0Xd530, 0X5aa0, _
0X6b50, 0X96d0, 0X4ae8, 0X4ad0, 0Xa4d0, 0Xd258, 0Xd250, 0Xd520, 0Xdaa0, 0Xb5a0, _
0X56d0, 0X4ad8, 0X49b0, 0Xa4b8, 0Xa4b0, 0Xaa50, 0Xb528, 0X6d20, 0Xada0, 0X55b0]
Global $gLunarMonth = _
[0X00, 0X50, 0X04, 0X00, 0X20, _
0X60, 0X05, 0X00, 0X20, 0X70, _
0X05, 0X00, 0X40, 0X02, 0X06, _
0X00, 0X50, 0X03, 0X07, 0X00, _
0X60, 0X04, 0X00, 0X20, 0X70, _
0X05, 0X00, 0X30, 0X80, 0X06, _
0X00, 0X40, 0X03, 0X07, 0X00, _
0X50, 0X04, 0X08, 0X00, 0X60, _
0X04, 0X0a, 0X00, 0X60, 0X05, _
0X00, 0X30, 0X80, 0X05, 0X00, _
0X40, 0X02, 0X07, 0X00, 0X50, _
0X04, 0X09, 0X00, 0X60, 0X04, _
0X00, 0X20, 0X60, 0X05, 0X00, _
0X30, 0Xb0, 0X06, 0X00, 0X50, _
0X02, 0X07, 0X00, 0X50, 0X03]
Global $gLunarFestival = _
["0101 春节", _
"0102 大年初二", _
"0103 大年初三", _
"0115 元宵", _
"0202 龙抬头", _
"0323 妈祖生辰", _
"0505 端午", _
"0707 七夕", _
"0715 中元", _
"0815 中秋", _
"0909 重阳", _
"1208 腊八", _
"1223 小年"]
Global $gSolarFestival = _
["0101 新年元旦", _
"0202 世界湿地日", _
"0207 国际声援南非日", _
"0210 国际气象节", _
"0214 情人节", _
"0301 国际海豹日", _
"0303 全国爱耳日", _
"0305 学雷锋纪念日", _
"0308 国际妇女节", _
"0312 植树节(孙中山逝世纪念日)", _
"0314 国际警察日", _
"0315 消费者权益日", _
"0317 国际航海日", _
"0321 世界森林日 世界儿歌日", _
"0322 世界水日", _
"0323 世界气象日", _
"0324 世界防结核病日", _
"0325 全国中小学安全日", _
"0330 巴勒斯坦国土日", _
"0401 愚人节", _
"0407 世界卫生日", _
"0422 世界地球日", _
"0423 世界图书版权日", _
"0424 亚非新闻工作者日", _
"0501 国际劳动节", _
"0504 五四青年节", _
"0505 碘缺乏防治日", _
"0508 世界红十字日", _
"0512 国际护士节", _
"0515 国际家庭日", _
"0517 世界电信日", _
"0518 国际博物馆日", _
"0520 学生营养日", _
"0523 国际牛奶日", _
"0531 世界无烟日", _
"0601 国际儿童节", _
"0605 世界环境日", _
"0606 全国爱眼日", _
"0617 防荒漠和干旱日", _
"0623 国际奥林匹克日", _
"0625 全国土地日", _
"0626 国际禁毒日", _
"0701 建党节 香港回归纪念", _
"0702 国际体育记者日", _
"0707 抗日战争纪念日", _
"0711 世界人口日", _
"0730 非洲妇女日", _
"0801 中国建军节", _
"0808 中国男子节(爸爸节)", _
"0815 日本投降日", _
"0908 国际扫盲日", _
"0910 教师节", _
"0914 世界清洁日", _
"0916 国际臭氧日", _
"0918 九·一八纪念", _
"0920 国际爱牙日", _
"0927 世界旅游日", _
"1001 国庆节", _
"1001 国际音乐日", _
"1002 国际和平日", _
"1004 世界动物日", _
"1008 全国高血压日", _
"1008 世界视觉日", _
"1009 万国邮联日", _
"1010 辛亥革命日", _
"1013 世界保健日", _
"1014 世界标准日", _
"1015 国际盲人节", _
"1016 世界粮食日", _
"1017 世界消贫日", _
"1022 世界医药日", _
"1024 联合国日", _
"1031 世界勤俭日", _
"1107 十月革命日", _
"1108 中国记者日", _
"1109 全国消防日", _
"1110 世界青年节", _
"1111 国际科学与和平周", _
"1112 孙中山诞辰", _
"1114 世界糖尿病日", _
"1117 世界学生节", _
"1121 世界问候日", _
"1129 国际声援巴日", _
"1201 世界艾滋病日", _
"1203 世界残疾人日", _
"1205 国际经社发展日", _
"1208 国际儿童电视日", _
"1209 世界足球日", _
"1210 世界人权日", _
"1212 西安事变日", _
"1213 南京大屠杀", _
"1220 澳门回归纪念", _
"1221 国际篮球日", _
"1224 平安夜", _
"1225 圣诞节", _
"1229 国际生物多样日"]
Const $boxStyle = 8192 + 262144
Global $sY, $sM, $sD, $bLeapMon, $strAM, $strPM, $strTimeFormat
$strDate = _NowCalcDate()
LunarDate(@YEAR, @MON, @MDAY)
$strHD = FormatHD(@YEAR, @MON, @MDAY)
$strLF = FormatLF($sM, $sD)
$strSF = FormatSF(@MON, @MDAY)
;~ MakeSLForm()
Func FormatLunarYr($year,$sx=1) ;get lunar year information
Local $TianGan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]
Local $DiZhi = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]
Local $ShengXiao = ["鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"]
$year -= 4
if $sx=1 Then
Return $TianGan & $DiZhi & $ShengXiao & "年"
Else
Return $TianGan & $DiZhi & "年"
EndIf
EndFunc ;==>FormatLunarYr
Func FormatLunarMon($mon) ;get lunar month information
Local $LunaMonth = ["正", "二", "三", "四", "五", "六", "七", "八", "九", "十"]
Local $strLeapPre = ""
If $bLeapMon = 1 Then $strLeapPre = "闰"
If $mon <= 10 Then Return $strLeapPre & $LunaMonth[$mon - 1] & "月"
If $mon = 11 Then
Return $strLeapPre & "十一月"
Else
Return $strLeapPre & "腊月"
EndIf
EndFunc ;==>FormatLunarMon
Func FormatLunarDay($day) ;get lunar day information
Local $Decimal = ["初", "十", "廿", "三"]
Local $Individual = ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十"]
If $day <> 20 And $day <> 30 Then
$day -= 1
Return $Decimal & $Individual
Else
Return $Decimal[$day / 10] & $Individual
EndIf
EndFunc ;==>FormatLunarDay
Func FormatHD($year, $mon, $day) ;get 节气
Local $HD = ["小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"]
;每年的正小寒点到各节气正节气点(即十五度倍数点)的分钟数
Local $sInfo =
$sMon = ($mon - 1) * 2
$offsec = Floor(31556925.9747 * ($year - 1900) + $sInfo[$sMon] * 60) ; offset seconds, 31556925974.7 地球公转周期,是毫秒
$offDate = _DateAdd('s', $offsec, '1900/01/06 02:05:00')
$sDay = Int(StringMid($offDate, 9, 2))
ConsoleWrite($offDate & @CRLF)
If $day = $sDay Then
Return "〖" & $HD[$sMon] & "〗"
Else
$sMon = ($mon - 1) * 2 + 1;
$offsec = Floor(31556925.9747 * ($year - 1900) + $sInfo[$sMon] * 60)
$offDate = _DateAdd('s', $offsec, '1900/01/06 02:05:00')
$sDay = Int(StringMid($offDate, 9, 2))
ConsoleWrite($offDate & @CRLF)
If $day = $sDay Then
Return "〖" & $HD[$sMon] & "〗"
Else
Return ""
EndIf
EndIf
EndFunc ;==>FormatHD
Func LunarDate($year, $mon, $day)
Local $lyrdays, $lmondays
Local $Diff = CalcDateDiff($year, $mon, $day)
$bLeapMon = 0
If $Diff < 49 Then
$sY = 1900 ;still in lunar year 1900
If $Diff < 19 Then
$sM = 11
$sD = 11 + $Diff
Else
$sM = 12
$sD = $Diff - 18
EndIf
Else
$Diff -= 49
$sY = 1901
$sM = 1
$sD = 1
;Get year
$lyrdays = LunarYearDays($sY)
While $Diff >= $lyrdays
$Diff -= $lyrdays
$sY += 1
$lyrdays = LunarYearDays($sY)
WEnd
;Get month
$lmondays = Mod(LunarMonthDays($sY, $sM), 256)
While $Diff >= $lmondays
$Diff -= $lmondays
;deal with leap month
If $sM = GetLeapMonth($sY) Then
$lmondays = Floor(LunarMonthDays($sY, $sM) / 256)
If $Diff < $lmondays Then
$bLeapMon = 1
ExitLoop
EndIf
$Diff -= $lmondays
EndIf
$sM += 1
$lmondays = Mod(LunarMonthDays($sY, $sM), 256)
WEnd
$sD += $Diff
EndIf
EndFunc ;==>LunarDate
Func CalcDateDiff($year, $mon, $day)
Local $monthday =
Local $Diff = ($year - 1901) * 365
$Diff += Floor(($year - 1) / 4) - Floor(1900 / 4)
$Diff -= Floor(($year - 1) / 100) - Floor(1900 / 100)
$Diff += Floor(($year - 1) / 400) - Floor(1900 / 400)
If _DateIsLeapYear($year) And $mon > 2 Then
$Diff += $monthday[$mon - 1] + 1
Else
$Diff += $monthday[$mon - 1]
EndIf
$Diff += $day - 1
Return $Diff
EndFunc ;==>CalcDateDiff
Func LunarYearDays($year)
Local $days = 0
Local $lmondays = 0
For $i = 1 To 12
$lmondays = LunarMonthDays($year, $i);
$days += Floor($lmondays / 256)
$days += Mod($lmondays, 256)
Next
Return $days
EndFunc ;==>LunarYearDays
Func LunarMonthDays($year, $mon)
Local $height = 0
Local $low = 29
Local $iBit = 16 - $mon
Local $lY = GetLeapMonth($year)
If $lY <> 0 And $mon > $lY Then $iBit = $iBit - 1
Local $intMove = -1 * $iBit
If BitAND($gLunarMonthDay[$year - 1901], BitShift(1, $intMove)) Then $low += 1
;deal with leap month days
If $mon = $lY Then
$intMove = -1 * ($iBit - 1)
If BitAND($gLunarMonthDay[$year - 1901], BitShift(1, $intMove)) Then
$height = 30
Else
$height = 29
EndIf
EndIf
Return $height * 256 + $low
EndFunc ;==>LunarMonthDays
Func GetLeapMonth($year);return the leap month in the specified solar year, if no, return 0
Local $flag = $gLunarMonth
If Mod($year - 1901, 2) Then
Return BitAND($flag, 0x0f)
Else
Return BitShift($flag, 4)
EndIf
EndFunc ;==>GetLeapMonth
Func SolarDate($year, $mon, $day)
Local $sMonthday =
Local $Diff = 0
Local $lmondays = 0
For $i = 1901 To $year - 1
$Diff += LunarYearDays($i)
Next
For $i = 1 To $mon - 1
$lmondays = LunarMonthDays($year, $i)
$Diff += Floor($lmondays / 256)
$Diff += Mod($lmondays, 256)
Next
If $bLeapMon = 1 Then $Diff += Mod(LunarMonthDays($year, $mon), 256) ;add the non-leap month days
$Diff += $day
$Diff += 49
$sYear = 1901
$sMon = 1
$sDay = 1
While $Diff > 365
If _DateIsLeapYear($sYear) Then
If $Diff = 366 Then ExitLoop
$Diff -= 366
Else
$Diff -= 365
EndIf
$sYear += 1
WEnd
While $Diff > $sMonthday[$sMon - 1]
$Diff -= $sMonthday[$sMon - 1]
If _DateIsLeapYear($sYear) And $sMon = 2 Then $Diff -= 1
$sMon += 1
WEnd
Return StringFormat("%04d/%02d/%02d", $sYear, $sMon, $Diff)
EndFunc ;==>SolarDate
Func FormatLF($mon, $day)
Local $bMatch = 0
For $i = 0 To UBound($gLunarFestival) - 1
If StringLeft($gLunarFestival[$i], 4) = StringFormat("%02d", $mon) & StringFormat("%02d", $day) Then
$bMatch = 1
If $bLeapMon = 1 And StringLeft($gLunarFestival[$i], 4) = "0715" Then $bMatch = 0 ;闰月无中元节
ExitLoop
EndIf
Next
If $bMatch = 1 Then
Return "【" & StringMid($gLunarFestival[$i], 6) & "】"
Else
Return ""
EndIf
EndFunc ;==>FormatLF
Func FormatSF($mon, $day)
Local $bMatch = 0
For $i = 0 To UBound($gSolarFestival) - 1
If StringLeft($gSolarFestival[$i], 4) = StringFormat("%02d", $mon) & StringFormat("%02d", $day) Then
$bMatch = 1
ExitLoop
EndIf
Next
If $bMatch = 1 Then
Return "『" & StringMid($gSolarFestival[$i], 6) & "』"
Else
Return ""
EndIf
EndFunc ;==>FormatSF
[ 本帖最后由 l4ever 于 2008-9-10 12:55 编辑 ] MakeSLForm()
Func MakeSLForm()
Local $strLeap
;If @Unicode Then
$DTM_SETFORMAT = 0x1032
;Else
;$DTM_SETFORMAT = 0x1005
;EndIf
#Region ### START Koda GUI section ### Form=
$SLForm = GUICreate("没什么特别的:)", 200, 88, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
$SDate = GUICtrlCreateDate(_NowCalcDate(), 75, 15, 120, 21)
$Label1 = GUICtrlCreateLabel("阳历:", 9, 18, 60, 17)
$LDate = GUICtrlCreateDate($sY & "/" & StringFormat("%02d", $sM) & "/" & StringFormat("%02d", $sD), 75, 57, 120, 21)
$Label2 = GUICtrlCreateLabel("农历:", 9, 60, 60, 17)
$Label3 = GUICtrlCreateLabel(FormatLunarYr($sY), 9, 39, 60, 17)
$sFormat = "yyyy/MM/dd"
GUICtrlSendMsg($SDate, $DTM_SETFORMAT, 0, $sFormat)
GUICtrlSendMsg($LDate, $DTM_SETFORMAT, 0, $sFormat)
$strHD = FormatHD(@YEAR, @MON, @MDAY)
$strLF = FormatLF($sM, $sD)
$strSF = FormatSF(@MON, @MDAY)
If $bLeapMon = 1 Then
$strLeap = FormatLunarMon($sM)
$bLeapMon = 0
Else
$strLeap = ""
EndIf
If $strHD <> "" Or $strLF <> "" Or $strSF <> "" Or $strLeap <> "" Then
WinSetTitle($SLForm, "", $strLeap & $strHD & $strLF & $strSF)
Else
WinSetTitle($SLForm, "", "没什么特别的:)")
EndIf
GUISetState(@SW_SHOW, $SLForm)
#EndRegion ### END Koda GUI section ###
While 1
$sMsg = GUIGetMsg(1)
Switch $sMsg
Case $GUI_EVENT_CLOSE
GUIDelete($SLForm)
ExitLoop
Case $SDate, $GUI_EVENT_PRIMARYUP
$bLeapMon = 0
If $sMsg = $GUI_EVENT_PRIMARYUP And $sMsg < 0 Then GUICtrlSetData($SDate, _NowCalcDate()) ;left double click will return to current date
If _DateDiff("D", "1901/02/19", GUICtrlRead($SDate)) < 0 Then GUICtrlSetData($SDate, "1901/02/19")
If _DateDiff("D", "2051/02/10", GUICtrlRead($SDate)) > 0 Then GUICtrlSetData($SDate, "2051/02/10")
$arrayDate = StringSplit(GUICtrlRead($SDate), "/")
LunarDate($arrayDate, $arrayDate, $arrayDate)
GUICtrlSetData($LDate, $sY & "/" & StringFormat("%02d", $sM) & "/" & StringFormat("%02d", $sD))
GUICtrlSetData($Label3, FormatLunarYr($sY))
If $bLeapMon = 1 Then
$strLeap = FormatLunarMon($sM)
$lmondays = Floor(LunarMonthDays($sY, $sM) / 256)
Else
$strLeap = ""
$lmondays = Mod(LunarMonthDays($sY, $sM), 256)
EndIf
If $sD = $lmondays And $sM = 12 Then $strLF = "【除夕】"
$strHD = FormatHD($arrayDate, $arrayDate, $arrayDate)
If $strLF <> "【除夕】" Then $strLF = FormatLF($sM, $sD)
$strSF = FormatSF($arrayDate, $arrayDate)
If $strHD <> "" Or $strLF <> "" Or $strSF <> "" Or $strLeap <> "" Then
WinSetTitle($SLForm, "", $strLeap & $strHD & $strLF & $strSF)
$strLeap = ""
$strHD = ""
$strLF = ""
$strSF = ""
Else
WinSetTitle($SLForm, "", "没什么特别的:)")
EndIf
Case $LDate
$bLeapMon = 0
If _DateDiff("D", "1901/01/01", GUICtrlRead($LDate)) < 0 Then GUICtrlSetData($LDate, "1901/01/01")
If _DateDiff("D", "2050/12/29", GUICtrlRead($LDate)) > 0 Then GUICtrlSetData($LDate, "2050/12/29")
$arrayDate = StringSplit(GUICtrlRead($LDate), "/")
If $arrayDate = GetLeapMonth($arrayDate) Then
If MsgBox(4 + 32 + $boxStyle, "Question", "This lunar month could be leap month." & @CRLF & "Is it a leap month?") = 6 Then
$bLeapMon = 1
$lmondays = Floor(LunarMonthDays($arrayDate, $arrayDate) / 256)
Else
$bLeapMon = 0
$lmondays = Mod(LunarMonthDays($arrayDate, $arrayDate), 256)
EndIf
Else
$lmondays = Mod(LunarMonthDays($arrayDate, $arrayDate), 256)
EndIf
If $arrayDate > $lmondays Then ;if the day is not in that luna month
If $arrayDate < 12 Then
GUICtrlSetData($LDate, StringFormat("%04d/%02d/%02d", $arrayDate, $arrayDate + 1, $arrayDate - $lmondays))
Else
GUICtrlSetData($LDate, StringFormat("%04d/%02d/%02d", $arrayDate + 1, 1, $arrayDate - $lmondays))
EndIf
$arrayDate = StringSplit(GUICtrlRead($LDate), "/")
Else
If $arrayDate = $lmondays And $arrayDate = 12 Then $strLF = "【除夕】"
EndIf
$solardate = SolarDate($arrayDate, $arrayDate, $arrayDate)
GUICtrlSetData($SDate, $solardate)
GUICtrlSetData($Label3, FormatLunarYr($arrayDate))
If $bLeapMon = 1 Then
$strLeap = FormatLunarMon($arrayDate)
Else
$strLeap = ""
EndIf
$arraySDate = StringSplit($solardate, "/")
$strHD = FormatHD($arraySDate, $arraySDate, $arraySDate)
If $strLF <> "【除夕】" Then $strLF = FormatLF($arrayDate, $arrayDate)
$strSF = FormatSF($arraySDate, $arraySDate)
If $strHD <> "" Or $strLF <> "" Or $strSF <> "" Or $strLeap <> "" Then
WinSetTitle($SLForm, "", $strLeap & $strHD & $strLF & $strSF)
$strLeap = ""
$strHD = ""
$strLF = ""
$strSF = ""
Else
WinSetTitle($SLForm, "", "没什么特别的:)")
EndIf
EndSwitch
WEnd
EndFunc ;==>MakeSLForm
放到楼上代码最后,运行之.
[ 本帖最后由 pcbar 于 2008-9-10 08:29 编辑 ] 能不能说说是根据什么原理编写的? 太好了,收藏代码. 收藏好帖子是个好习惯! 回复 1# l4ever
有现成的udf吗? 当然,网上也有很多高级语言编写的相关控件或函数。
只是,如果用AutoIt的话,还是用UDF好些。 厉害,收下源码了{:face (282):} 运行有问题。。。。。
--> 点击 Ctrl+Alt+Break 重新启动, 或 Ctrl+Break 停止脚本执行
2016/08/07 11:04:53
"X:\??????.au3" (450) : ==> ?????????, ?????????.:
LunarDate($arrayDate, $arrayDate, $arrayDate)
LunarDate($arrayDate, ^ ERROR
->19:49:57 AutoIt3.exe 结束.rc: 1
页:
[1]