简体   繁体   中英

Date time formats in PHP

I'm using the GoTo Webinar API and it expects a date format as shown below in the start time and end time elements of the array:

$params = [
    'subject' => 'Test 34',
    'description' => 'Test test test lalala',
    'times' => [[
        'startTime' => '2016-02-22T23:00:00Z',
        'endTime' => '2016-02-23T00:00:00Z'
    ]],
    'timeZone' => 'GMT'
];

Could somebody explain to me what the relevance of the T/Z means eitherside of the time part? Does this just mean apply the TimeZone element of GMT which is also passed in below?

If so, can I/how do I use the PHP date() function to format this: "2016-01-16 07:00:00" into the above format?

The data standard used.

They follow the ISO 8601 standard. You can find more details about this standard at eg. the Wikipedia article on ISO 8601 .


About the meaning of the T :

A single point in time can be represented by concatenating a complete date expression, the letter T as a delimiter, and a valid time expression. For example, "2007-04-05T14:30".

About the meaning of the Z :

If the time is in UTC, add a Z directly after the time without a space. Z is the zone designator for the zero UTC offset. "09:30 UTC" is therefore represented as "09:30Z" or "0930Z". "14:45:15 UTC" would be "14:45:15Z" or "144515Z".

How to format a date according to the ISO 8601 standard in PHP :

$datetime = new DateTime('2016-01-25 23:46:46');
$datetime->format(DateTime::ISO8601);

The value Z itself only indicates a standard UTC Time (it means Zulu Time). It is used according the ISO 8601. So you can use something like date(DateTime::ISO8601) , and it should produce the output that you wants.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM