Guest User

Untitled

a guest
Jun 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. Output:
  2. ======
  3. Test... int(0) 0 0 0 0 9 0
  4. 9
  5.  
  6.  
  7. Test Code:
  8. ======
  9.  
  10. Test...
  11.  
  12. <?php
  13.  
  14. error_reporting(E_ALL);
  15. ini_set("display_errors", 1);
  16.  
  17. $total = 0;
  18.  
  19. $january = new DateTime('2010-01-01 00:00:01');
  20. $february = new DateTime('2010-01-01 00:09:01');
  21. $interval = $february->diff($january);
  22.  
  23. $year = $interval->format('%y');
  24. $month = $interval->format('%m');
  25. $days = $interval->format('%a');
  26. $hours = $interval->format('%h');
  27. $minutes = $interval->format('%i');
  28. $seconds = (int) $interval->format('%s'); var_dump($seconds); // int(0) $interval->s;
  29.  
  30. $total += ($seconds >0 ) ? 1 : 0;
  31. $total += ($minutes >0 ) ? $minutes : 0;
  32. $total += ($hours >0 ) ? ($hours * 60) : 0;
  33. $total += ($days >0 ) ? (($days * 24) * 60) : 0;
  34.  
  35.  
  36. echo $year . ' ' . $month . ' ' . $days . ' ' . $hours . ' ' . $minutes . ' ' . $seconds . '<br/>';
  37.  
  38. echo $total;
  39.  
  40. ?>
Add Comment
Please, Sign In to add comment