高分请教,日历的算法!!!!
最好详细一点
---------------------------------------------------------------
以前的收藏,看对你是否有用?
1'获取正确的日期
2Function YmdList(yi,mi,di)
3Dim y,m,d
4'年
5if yi="" or isnumeric(yi)=false then
6y=year(now())
7else
8y=yi
9end if
10
11'月
12if mi="" or isnumeric(mi)=false then
13m=Month(now())
14else
15m=mi
16end if
17if m>13 then m=13
18if m<1 then m=1
19
20'日
21if di="" or isnumeric(di)=false then
22d=day(now())
23else
24d=di
25end if
26if m=2 and d>28 then
27if y mod 4=0 then
28if y mod 100=0 then
29if y mod 1000=0 then
30d=29
31else
32d=28
33end if
34else
35d=29
36end if
37else
38d=28
39end if
40end if
41if (m=4 or m=6 or m=9 or m=11) and d>30 then d=30
42if d<1 then d=1
43YmdList=cstr(y)&"-"&cstr(m)&"-"&cstr(d)
44End Function
1'获取正确的日期时间
2Function YmdHms(yi,mi,di,hi,msi,si)
3dim h,ms,s
4
5'时
6if hi="" or isnumeric(hi)=false then
7h=0
8else
9h=hi
10end if
11if h<0 then h=0
12if h>=24 then h=23
13
14'分
15if msi="" or isnumeric(msi)=false then
16ms=0
17else
18ms=msi
19end if
20if ms<0 then ms=0
21if ms>=60 then ms=59
22
23'秒
24if si="" or isnumeric(si)=false then
25s=0
26else
27s=si
28end if
29if s<0 then s=0
30if s>=60 then s=59
31YmdHms=YmdList(yi,mi,di)&" "&h&":"&ms&":"&s
32End Function
1'每月的天数
2Function MonthDays(Yeari,Monthi)
3Dim Days
4Days=0
5if Monthi=2 then
6if Yeari mod 4=0 then
7if Yeari mod 100=0 then
8if Yeari mod 1000=0 then
9Days=29
10else
11Days=28
12end if
13else
14Days=29
15end if
16else
17Days=28
18end if
19else
20if Monthi=4 or Monthi=6 or Monthi=9 or Monthi=11 then
21Days=30
22else
23Days=31
24end if
25end if
26MonthDays=Days
27End Function
1'每天是星期几
2Function DayWeek(Yeari,Monthi,Dayi)
3Dim Days
4Days=0
5Dim yi,mi
6'年
7For yi=2001 to Yeari-1
8if yi mod 4=0 then
9if yi mod 100=0 then
10if yi mod 1000=0 then
11Days=Days+366
12else
13Days=Days+365
14end if
15else
16Days=Days+366
17end if
18else
19Days=Days+365
20end if
21Next
22'月
23For mi=1 to Monthi-1
24Days=Days+MonthDays(Yeari,mi)
25Next
26Days=Days+Dayi
27DayWeek=Days mod 7
28End Function
1'星期的中文表示方法
2Function WeekName(wi)
3Select case wi
4case 0
5WeekName="日"
6case 1
7WeekName="一"
8case 2
9WeekName="二"
10case 3
11WeekName="三"
12case 4
13WeekName="四"
14case 5
15WeekName="五"
16case 6
17WeekName="六"
18End Select
19WeekName="星期"&WeekName
20End Function
21
22
23function FirstDayOfWeek (nYear, nIndex)
24dim dt, n
25dt = dateserial(nYear, 1,1)
26n = weekday(dt)
27if n > 2 then
28dt = dateadd("d", 7-n+2 , dt)
29else
30dt = dateadd("d", 2-n , dt)
31end if
32
33if nIndex > 1 then
34dt = dateadd("d", 7*(nIndex-1) , dt)
35end if
36FirstDayOfWeek = dt
37end function