Could there be a way to add microseconds or milliseconds somehow or is there a way already?
Currently its not supported. Only reading the current value is supported.
If the constructor generates "now" using a timestamp with microseconds, then DateTime will store that internally. ie.
list($usec, $sec) = explode(' ', microtime());
$dt = new DateTime(date('Y-m-d\TH:i:s', $sec) . substr($usec, 1));
echo $dt->format('Y-m-d\TH:i:s.u');
It's messy, but it works!
Still not works for version 1.21.0.
In the meantime, why not convert the milliseconds to the seconds by driving it to the thousand?
Example for Laravel:
Carbon::createFromTimestamp(1467507452744 / 1000)->diffForHumans(); // 1 second ago
:+1:
馃憤
This would be great to have baked in as MongoDB for PHP gives you back milliseconds, the code suggestion above is working for me so I'll be using that until this is added in
+1
Not a full implementation, but you can now create an instance with milliseconds. #988 988
Most helpful comment
Not a full implementation, but you can now create an instance with milliseconds. #988 988