Skip to content

Instantly share code, notes, and snippets.

@tarnfeld
Created March 22, 2012 00:42
Show Gist options
  • Select an option

  • Save tarnfeld/2154723 to your computer and use it in GitHub Desktop.

Select an option

Save tarnfeld/2154723 to your computer and use it in GitHub Desktop.
Clock
<?php
function diff($hours, $minutes)
{
// get the degrees for each part
$hour_deg = 360/12;
$min_deg = 360/60;
// calculate the position
$hour_hand = $hour_deg*$hours;
$min_hand = $min_deg*$minutes;
// diff
return max($hour_hand, $min_hand) - min($hour_hand, $min_hand);
}
var_dump(diff(9,15)); // 180
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment