We need to calculate Degree of angle between hour and minute hand Sometimes.
So I wrote a function to solve it:
- FunctionHourhandminute(ByValmytimeAsDate)AsString
- DimtAsSingle,hAsLong,mAsLong,sAsLong
- h=Hour(mytime)
- m=Minute(mytime)
- s=Second(mytime)
- Ifh>11Thenh=h-12
- t=Abs(11*m/2-30*h+11*s/120)
- Ift>180Thent=360-t
- Hourhandminute=Abs(t)
- EndFunction
Errors may be occured because of the calculating precision. But in most occasions,the results were right.
For example:
- SubGetall()
- DimiAsSingle
- Fori=0To1Step1/86400
- IfAbs(Hourhandminute(i)-180)<0.09ThenDebug.PrintFormat(i,"hh:mm:ss")
- Next
- EndSub
It will return the time when the degree of angle between hour and minute hand is 180°
00:32:43
01:38:10
02:43:38
03:49:05
04:54:32
06:00:00
07:05:28
08:10:55
09:16:22
10:21:50
11:27:17
12:32:43
13:38:10
14:43:38
15:49:05
16:54:32
18:00:00
19:05:28
20:10:55
21:16:22
22:21:50
23:27:17
本文介绍了一个用于计算时钟上时针与分针之间角度的VBScript函数。该函数考虑了小时、分钟和秒数,通过精确计算返回两者之间的角度值。文章还提供了一个示例子程序,用于找出时钟上时针与分针成180°角的所有时刻。
1万+

被折叠的 条评论
为什么被折叠?



