Guest User

Untitled

a guest
Apr 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. ## microtime_date.php
  2. <?php
  3.  
  4. function microtime_date($str, $timestamp = NULL) {
  5. /* Use 'x' as the microseconds */
  6. if (is_null($timestamp)) {
  7. $timestamp = microtime();
  8. } elseif (is_integer($timestamp)) {
  9. $timestamp = sprintf("0.00000000 %d", $timestamp);
  10. }
  11. list($fractional, $seconds) = split(" ",strval($timestamp));
  12. $microseconds = sprintf("%08d", $fractional*100000000);
  13. $str = str_replace("x", $microseconds, $str);
  14. return date($str, $seconds);
  15. }
  16.  
  17. for ($i = 1; $i<100; $i++) {
  18. $x = array();
  19. for ($j = 1; $j<5000000; $j++) {
  20. $x[] = $j;
  21. if ($j%1000==0) {
  22. $x = array();
  23. }
  24. }
  25. $t = time();
  26. $m = microtime();
  27. $v = microtime_date("Y-m-d H:i:s.x", $m);
  28. printf ( "Time: %s Microtime: %s Date with microseconds: %s\n", $t, $m, $v);
  29. }
  30.  
  31. ?>
  32.  
  33. ## How to run it
  34. php -qC microtime_date.php
  35.  
  36. ## Output
  37.  
  38. Time: 1208365730 Microtime: 0.00431900 1208365730 Date with microseconds: 2008-04-16 12:08:50.00431900
  39. Time: 1208365733 Microtime: 0.93399600 1208365733 Date with microseconds: 2008-04-16 12:08:53.93399600
  40. Time: 1208365737 Microtime: 0.87001500 1208365737 Date with microseconds: 2008-04-16 12:08:57.87001500
  41. Time: 1208365741 Microtime: 0.80376300 1208365741 Date with microseconds: 2008-04-16 12:09:01.80376300
  42. Time: 1208365745 Microtime: 0.74578500 1208365745 Date with microseconds: 2008-04-16 12:09:05.74578500
  43. Time: 1208365749 Microtime: 0.68914500 1208365749 Date with microseconds: 2008-04-16 12:09:09.68914500
  44. Time: 1208365753 Microtime: 0.64018500 1208365753 Date with microseconds: 2008-04-16 12:09:13.64018500
Add Comment
Please, Sign In to add comment