We need to calculate Degree of angle between hour and minute hand Sometimes.
So I wrote a function to solve it:
- Function Hourhandminute(ByVal mytime As Date) As String
- Dim t As Single, h As Long, m As Long, s As Long
- h = Hour(mytime)
- m = Minute(mytime)
- s = Second(mytime)
- If h > 11 Then h = h - 12
- t = Abs(11 * m / 2 - 30 * h+11 * s / 120)
- If t > 180 Then t = 360 - t
- Hourhandminute = Abs(t)
- End Function
Errors may be occured because of the calculating precision. But in most occasions,the results were right.
For example:
- Sub Getall()
- Dim i As Single
- For i = 0 To 1 Step 1 / 86400
- If Abs(Hourhandminute(i) - 180) < 0.09 Then Debug.Print Format(i, "hh:mm:ss")
- Next
- End Sub
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