Search code examples
phpdatetimeebay-api

Creating datetime for ebay with php


I cannot create a valid datetime with php for ebay finding api.

According to their api, the datetime value should look like this

2004-08-04T19:09:02.768Z

I found in the php documentation that there is a special notation for ISO 8601 with (new DateTime())->format('c') but it does not give me the correct date.

Anyone know how to create one?


Solution

  • Try This:

    <?php
        $time = microtime(true);
        $tMicro = sprintf("%03d",($time - floor($time)) * 1000);
        $tUtc = gmdate('Y-m-d\TH:i:s.', $time).$tMicro.'Z';
        echo $tUtc;
    ?>