douyou1937 2016-02-25 10:56
浏览 191
已采纳

从PHP DateTime对象获取带小数的纪元时间?

$d = new \DateTime("2016-02-25 19:14:10.080415");

echo floatval($d->getTimestamp() . $d->format(".u")), "
";  // 1456424050.0804

This works, but feels very akward. Is there any better way to get a floating point number of seconds from a DateTime object? I'm looking for the same value that microtime(true) would return for the current time.

  • 写回答

1条回答 默认 最新

  • duanaoou4105 2016-02-25 10:59
    关注

    Yes, there is an easier way

    echo $d->format('U.u');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?