Clock Hands

Given a time of day, determine the angles in degrees of the hands for an analog clock.

The minute hand always lands discretely on a minute but the hour hand position takes into consideration the minutes.

Calculating the minute position is straightforward. Since the hour hand position accounts for the minutes as well, the hour hand must be placed fractionally ahead for each minute in the time. For example, at 1 o’clock the hour hand is exactly on the hour, but at 1:30 the hour hand is placed halfway between 1:00 and 2:00.

func minutesToDegrees(m: Int) -> Int {
  // = 360 / 60 * m = 6m
  return 6 * m
}

func hoursToDegrees(h: Int, m: Int) -> Int {
  // = 360 / 12 * h + (360 / 12 * m / 60) = 30h + m/2
  return 30 * h + m / 2
}
Scroll to top