前言:
算法公式是foxjl从网上找来的,本人只是将这种算法用VBS实现而已,没有什么技术含量,也不敢妄称原创。
代码中的经度和纬度是本人所在地株洲市的,时区是东8区,大家可以修改这三个变量的值来计算各地的日落时间。- Dim JD, WD, Days, SunDown, TimeArea, X, ACOS, Arr, Today
- JD = 113.8 '经度,东为正西为负,我国都是东经
- WD = 27.55 '纬度,北为正南为负,我国都是北纬
- TimeArea = 8 '时区,东正西负,我国有东九、东八、东七、东六、东五五个时区
- TodAy = Year(Now) & "年" & Month(Now) & "月" & Day(Now) & "日"
- Days = DateDiff("d", Year(Now) & "-1-1 00:00:00", Now) + 1
- X = -TAN(-23.4*COS(2*3.14*(Days+9)/365)*3.14/180)*TAN(WD*3.14/180)
- ACOS = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
- SunDown = Round(24*(1+(TimeArea*15-JD)/180)-24*(180+TimeArea*15-JD-ACOS*180/3.14)/360, 2)
- Arr = Split(SunDown, ".")
- SunDown = Arr(0) & ":" & Int((0&"."&Int(Arr(1)))*60)
- WScript.Echo "本地" & Today & "的日落时间为:" & SunDown
复制代码
|