Last active
August 29, 2015 14:25
-
-
Save marcojetson/553c772a8d8740938982 to your computer and use it in GitHub Desktop.
DateTime supporting microseconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class IDateTime extends \DateTime | |
{ | |
public function __construct($time = 'now', $timezone = null) | |
{ | |
if ($time === null || $time === 'now') { | |
$ts = microtime(true); | |
$micro = sprintf('%06d',($ts - floor($ts)) * 1000000); | |
$time = date('Y-m-d H:i:s.' . $micro, $ts); | |
} | |
return parent::__construct($time, $timezone); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment