欢迎光临
我们一直在努力

纯ASP代码之公历转农历实现(含属相)-ASP教程,ASP应用

建站超值云服务器,限时71元/月

 

<%
option explicit
***********************************************
类名称:chinaday
用途:
  根据输入的日期计算该日期的农历天干地支及当年属相
使用方法:
第一个参数为输入参数,不填写默认为当日,
只计算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(阿泰)
mail:  babyt@mail.csdn.net
welcome to:
   http://blog.csdn.net/babyt/
   http://www.facesun.cn
created at: 2005-2-20
copyright: 本代码非原创,是2001年收集的,原作者未知。
license:free
*******************************************************
class chinaday
 
 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
 
 初始化数据
 sub class_initialize()
  —————————————————
  定义显示字串
 
  星期名
  arrweekname(0) = “*”
  arrweekname(1) = “星期日”
  arrweekname(2) = “星期一”
  arrweekname(3) = “星期二”
  arrweekname(4) = “星期三”
  arrweekname(5) = “星期四”
  arrweekname(6) = “星期五”
  arrweekname(7) = “星期六”
 
  天干名称
  arrtiangan(0) = “甲”
  arrtiangan(1) = “乙”
  arrtiangan(2) = “丙”
  arrtiangan(3) = “丁”
  arrtiangan(4) = “戊”
  arrtiangan(5) = “己”
  arrtiangan(6) = “庚”
  arrtiangan(7) = “辛”
  arrtiangan(8) = “壬”
  arrtiangan(9) = “癸”
 
  地支名称
  arrdizhi(0) = “子”
  arrdizhi(1) = “丑”
  arrdizhi(2) = “寅”
  arrdizhi(3) = “卯”
  arrdizhi(4) = “辰”
  arrdizhi(5) = “巳”
  arrdizhi(6) = “午”
  arrdizhi(7) = “未”
  arrdizhi(8) = “申”
  arrdizhi(9) = “酉”
  arrdizhi(10) = “戌”
  arrdizhi(11) = “亥”
 
  属相名称
  arrshuxiang(0) = “鼠”
  arrshuxiang(1) = “牛”
  arrshuxiang(2) = “虎”
  arrshuxiang(3) = “兔”
  arrshuxiang(4) = “龙”
  arrshuxiang(5) = “蛇”
  arrshuxiang(6) = “马”
  arrshuxiang(7) = “羊”
  arrshuxiang(8) = “猴”
  arrshuxiang(9) = “鸡”
  arrshuxiang(10) = “狗”
  arrshuxiang(11) = “猪”
 
  农历日期名
  arrdayname(0) = “*”
  arrdayname(1) = “初一”
  arrdayname(2) = “初二”
  arrdayname(3) = “初三”
  arrdayname(4) = “初四”
  arrdayname(5) = “初五”
  arrdayname(6) = “初六”
  arrdayname(7) = “初七”
  arrdayname(8) = “初八”
  arrdayname(9) = “初九”
  arrdayname(10) = “初十”
  arrdayname(11) = “十一”
  arrdayname(12) = “十二”
  arrdayname(13) = “十三”
  arrdayname(14) = “十四”
  arrdayname(15) = “十五”
  arrdayname(16) = “十六”
  arrdayname(17) = “十七”
  arrdayname(18) = “十八”
  arrdayname(19) = “十九”
  arrdayname(20) = “二十”
  arrdayname(21) = “廿一”
  arrdayname(22) = “廿二”
  arrdayname(23) = “廿三”
  arrdayname(24) = “廿四”
  arrdayname(25) = “廿五”
  arrdayname(26) = “廿六”
  arrdayname(27) = “廿七”
  arrdayname(28) = “廿八”
  arrdayname(29) = “廿九”
  arrdayname(30) = “三十”
 
  农历月份名
  arrmonname(0) = “*”
  arrmonname(1) = “正”
  arrmonname(2) = “二”
  arrmonname(3) = “三”
  arrmonname(4) = “四”
  arrmonname(5) = “五”
  arrmonname(6) = “六”
  arrmonname(7) = “七”
  arrmonname(8) = “八”
  arrmonname(9) = “九”
  arrmonname(10) = “十”
  arrmonname(11) = “十一”
  arrmonname(12) = “腊”
 
  ———————————————————

  公差数据定义
 
  公历每月前面的天数
  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
 
  农历数据
  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
 
 ############################################################
 主要方法 action
  inday 输入日期,如果不输入则默认为当前日期
  sday 中文格式日期
  sweekday 周几
  schinayear 农历年
  schinaday 农历日
  schinaani 属相
 ############################################################
 public function action(inday,sday,sweekday,schinayear,schinaday,schinaani)
 
  转换要转换的日期
  if inday=”” or not isdate(inday) then
   获取当前系统时间
   curtime = now()
  else
   curtime = cdate(inday)
  end if
 
  if datediff(“d”,curtime,cdate(“1921-2-8”))>0 then
   exit function
  end if
 
  生成当前公历年、月、日 ==> sday
  curyear = year(curtime)
  curmonth = month(curtime)
  curday = day(curtime)
 
  sday = curyear&”年”
  if (curmonth < 10) then
   sday = sday&”0″&curmonth&”月”
  else
   sday = sday&curmonth&”月”
  end if
  if (curday < 10) then
   sday = sday&”0″&curday&”日”
  else
   sday = sday&curday&”日”
  end if
 
  生成当前公历星期 ==> sweekday
  curweekday = weekday(curtime)
  sweekday = arrweekname(curweekday)
 
  计算到初始时间1921年2月8日的天数:1921-2-8(正月初一)
  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
 
  计算农历天干、地支、月、日
  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
   
    获取nonglidata(m)的第n个二进制位的值
    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
 
  生成农历天干、地支==> schinayear
  schinayear = “农历”&arrtiangan(((curyear – 4) mod 60) mod 10)&arrdizhi(((curyear – 4) mod 60) mod 12)&”年”
  生成属相 == > schinaani
  schinaani = arrshuxiang(((curyear – 4) mod 60) mod 12)
 
  生成农历月、日 ==> nonglidaystr
  if (curmonth < 1) then
   schinaday = “闰”&arrmonname(-1 * curmonth)
  else
   schinaday = arrmonname(curmonth)
  end if
  schinaday = schinaday&”月”
 
  schinaday = schinaday & arrdayname(curday)
 end function
end class
%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 纯ASP代码之公历转农历实现(含属相)-ASP教程,ASP应用
分享到: 更多 (0)