Get the Degree of Angle Between Hour and Minute Hand of a Clock at Anytime

We need to calculate Degree of angle between hour and minute hand Sometimes.

So I wrote a function to solve it:

  1. FunctionHourhandminute(ByValmytimeAsDate)AsString
  2. DimtAsSingle,hAsLong,mAsLong,sAsLong
  3. h=Hour(mytime)
  4. m=Minute(mytime)
  5. s=Second(mytime)
  6. Ifh>11Thenh=h-12
  7. t=Abs(11*m/2-30*h+11*s/120)
  8. Ift>180Thent=360-t
  9. Hourhandminute=Abs(t)
  10. EndFunction

Errors may be occured because of the calculating precision. But in most occasions,the results were right.

For example:

  1. SubGetall()
  2. DimiAsSingle
  3. Fori=0To1Step1/86400
  4. IfAbs(Hourhandminute(i)-180)<0.09ThenDebug.PrintFormat(i,"hh:mm:ss")
  5. Next
  6. 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

你可能感兴趣的:(360)