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. Function Hourhandminute(ByVal mytime As DateAs String
  2. Dim t As Single, h As Long, m As Long, s As Long
  3. h = Hour(mytime)
  4. m = Minute(mytime)
  5. s = Second(mytime)
  6. If h > 11 Then h = h - 12
  7. t = Abs(11 * m / 2 - 30 * h+11 * s / 120)
  8. If t > 180 Then t = 360 - t
  9. Hourhandminute = Abs(t)
  10. End Function

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

 

For example:

 

 

  1. Sub Getall()
  2. Dim i As Single
  3. For i = 0 To 1 Step 1 / 86400
  4. If Abs(Hourhandminute(i) - 180) < 0.09 Then Debug.Print Format(i, "hh:mm:ss")
  5. Next
  6. 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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值