Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## microtime_date.php
- <?php
- function microtime_date($str, $timestamp = NULL) {
- /* Use 'x' as the microseconds */
- if (is_null($timestamp)) {
- $timestamp = microtime();
- } elseif (is_integer($timestamp)) {
- $timestamp = sprintf("0.00000000 %d", $timestamp);
- }
- list($fractional, $seconds) = split(" ",strval($timestamp));
- $microseconds = sprintf("%08d", $fractional*100000000);
- $str = str_replace("x", $microseconds, $str);
- return date($str, $seconds);
- }
- for ($i = 1; $i<100; $i++) {
- $x = array();
- for ($j = 1; $j<5000000; $j++) {
- $x[] = $j;
- if ($j%1000==0) {
- $x = array();
- }
- }
- $t = time();
- $m = microtime();
- $v = microtime_date("Y-m-d H:i:s.x", $m);
- printf ( "Time: %s Microtime: %s Date with microseconds: %s\n", $t, $m, $v);
- }
- ?>
- ## How to run it
- php -qC microtime_date.php
- ## Output
- Time: 1208365730 Microtime: 0.00431900 1208365730 Date with microseconds: 2008-04-16 12:08:50.00431900
- Time: 1208365733 Microtime: 0.93399600 1208365733 Date with microseconds: 2008-04-16 12:08:53.93399600
- Time: 1208365737 Microtime: 0.87001500 1208365737 Date with microseconds: 2008-04-16 12:08:57.87001500
- Time: 1208365741 Microtime: 0.80376300 1208365741 Date with microseconds: 2008-04-16 12:09:01.80376300
- Time: 1208365745 Microtime: 0.74578500 1208365745 Date with microseconds: 2008-04-16 12:09:05.74578500
- Time: 1208365749 Microtime: 0.68914500 1208365749 Date with microseconds: 2008-04-16 12:09:09.68914500
- Time: 1208365753 Microtime: 0.64018500 1208365753 Date with microseconds: 2008-04-16 12:09:13.64018500
Add Comment
Please, Sign In to add comment