timer.class.php 762 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. class timer
  3. {
  4. public $StartTime = 0;
  5. public $StopTime = 0;
  6. public $TimeSpent = 0;
  7. public function start()
  8. {
  9. $this->StartTime = microtime();
  10. }
  11. public function stop()
  12. {
  13. $this->StopTime = microtime();
  14. }
  15. public function spent()
  16. {
  17. if ($this->TimeSpent) {
  18. return $this->TimeSpent;
  19. }
  20. else {
  21. $StartMicro = substr($this->StartTime, 0, 10);
  22. $StartSecond = substr($this->StartTime, 11, 10);
  23. $StopMicro = substr($this->StopTime, 0, 10);
  24. $StopSecond = substr($this->StopTime, 11, 10);
  25. $start = doubleval($StartMicro) + $StartSecond;
  26. $stop = doubleval($StopMicro) + $StopSecond;
  27. $this->TimeSpent = $stop - $start;
  28. return substr($this->TimeSpent, 0, 8) . '秒';
  29. }
  30. }
  31. }
  32. !defined('IN_MYMPS') && exit('FORBIDDEN');
  33. ?>