这个日期时间字符串是什么格式:2001-12-17T09:30:47-05:00 [复制]

这个日期时间字符串是什么格式:2001-12-17T09:30:47-05:00 [复制]

问题描述:

This question already has an answer here:

I need to generate a MessageTime for a xml based api. In the example request file, they are using the following:

<MessageTime>2001-12-17T09:30:47-05:00</MessageTime>

What is the format of this datetime string? I want to generate it using date() method or DateTime class.

This is what I tried so far: I am in the UK, so i am using the offset 00:00

var_dump(date('Y-m-d\TH:i:s').'-00:00')
// Output: 2014-05-26T20:11:45-00:00

Is this correct?

</div>

此问题已经存在 这里有一个答案: p>

  • 为什么DateTime会在时间戳中添加T分隔符? 4 answers span> li> ul> div>

    我需要生成 MessageTime 代码>用于基于xml的api。 在示例请求文件中,他们使用以下内容: p>

     &lt; MessageTime&gt; 2001-12-17T09:30:47-05:00&lt; / MessageTime&gt; 
       pre> 
     
     

    此日期时间字符串的格式是什么? 我想使用 date() code>方法或 DateTime code>类生成它。 p>

    这是我到目前为止所尝试的: 我在英国,所以我使用偏移 00:00 code> em> p>

      var_dump(date('Ymd \ TH:i)  :s')。' -  00:00')
     //输出:2014-05-26T20:11:45-00:00 
      code>  pre> 
     
     

    这是 对吗? p> div>

ISO 8601 date (added in PHP 5):

date('c');

Or using a constant:

date(DateTime::ISO8601);

You can also utilize O for the "difference to Greenwich time (GMT) in hours":

date('Y-m-d\TH:i:sO');