get the ISO 8601 with seconds.decimal-fraction-of-second date in php?

前端 未结 5 1016
遇见更好的自我
遇见更好的自我 2020-12-16 19:26

I echo this :

  php> echo date(\"Y-m-d\\TH:i:s\");
      2011-05-27T11:21:23

How can do with date function to get this date format:

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 19:36

    By doing separate [date] calls you have a small chance of two time stamps being out of order: eg call date at 1:29:22.999999 and mircotime at 1:29:23.000001. On my server consecutive calls are about 10 us apart.

    Source

    Try this instead:

    list($usec, $sec) = explode(" ", microtime());
    echo date("Y-m-d\TH:i:s", $sec) . substr($usec, 1, 8) . date("P", $sec);
    

    E.g.:

    2015-07-19T16:59:16.0113674-07:00
    

提交回复
热议问题