Skip to content

Instantly share code, notes, and snippets.

@marcojetson
Last active August 29, 2015 14:25
Show Gist options
  • Save marcojetson/553c772a8d8740938982 to your computer and use it in GitHub Desktop.
Save marcojetson/553c772a8d8740938982 to your computer and use it in GitHub Desktop.
DateTime supporting microseconds
<?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