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

前端 未结 5 1018
遇见更好的自我
遇见更好的自我 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:33

    date('Y-m-d\TH:i:s.uP')
    

    u for microseconds was added in PHP 5.2.2. For earlier or (still) broken versions (see comments):

    date('Y-m-d\TH:i:s') . substr(microtime(), 1, 8) . date('P')
    

    Or, to avoid two calls to date:

    date(sprintf('Y-m-d\TH:i:s%sP', substr(microtime(), 1, 8)))
    

提交回复
热议问题