Calculate The Angle Between Hour Hand & Minute Hand In PHP

Calculate The Angle Between Hour Hand And Minute Hand In PHP [Example]

By Anand Lagad December 7, 2017 PHP

 

Question:
   12-hour analog clock and the time is given,

calculate the angle between hour hand & minute hand in php.

Time: 02:20;

The question is related to Clock Angle Problems.

Many times PHP Developers also facing such questions while interviewing.

To get hands-on experience in such questions you should study the Clock Angle Problem concept and formulae.

 

Pin Points:

 

  1. It is 12-hour analog clock so please start calculating angles and respective degree values from the mark of number 12 clockwise.
  2. Please check the image for given time. Many of the interviewees get confused between the exact place of Hour Hand and Minute Hand. The time is 2:20, many of interviewees consider the Hour hand at 2. Hour Hand is slightly ahead of 2.
  3. To calculate the angle between hour hand and minute hand we must
    • Calculate the angle made by hour hand with respect to 12:00 in $h hours and $m minutes.
    • Calculate the angle made by minute hand with respect to 12:00 in $h hours and $m minutes.
      The difference between these two angles is the angle between two hands.
  4. Draw a diagram as per above image for better understanding.

PHP CODE EXAMPLE: 

calculate the angle between hour hand & minute hand in php.

ANSWER:  50 Degrees.

Explanation:

  1. The Hour Hand moves 360 degrees in 12 hours i.e 720 minutes or 0.5 degrees in 1 minute. Therefore the formula for calculating hour hand angle is,
    hour_angle = 0.5 * ( hours *60 + minutes);
    Total time is converted into minutes and multiplied by 0.5 to get the number of degrees as a result.
  2. The Minute hand moves 360 degrees in 60 minutes i.e 6 degrees in 1 minute. Therefore the formula for calculating minute hand angle is,
    minute_angle = 6 * minutes;
    The total number of degrees are stored in minute_angle as a result of minute hand angle.
  3. By calculating the difference between these two angles we will get the angle between hour hand and minute hand.

Hope this helped! 🙂

 

Please comment if you have any doubt!

Blog Summary
Calculate The Angle Between Hour Hand & Minute Hand In PHP [Example]
Article Name
Calculate The Angle Between Hour Hand & Minute Hand In PHP [Example]
Description
Detailed example to Calculate The Angle Between Hour Hand & Minute Hand In PHP.Asked in many interviews for experienced candidates
Author
Publisher Name
Anand Lagad- Online Entrepreneur
Publisher Logo

Comments

Visit Us On FacebookVisit Us On PinterestVisit Us On TwitterVisit Us On LinkedinVisit Us On Instagram