Working with external API's I often encounter timestamps like these: 2021-11-15T23:15:35Z.

Each time I have to open the Carbon documentation and read through the entire thing with a magnifying glass to look for the format that ends with a Z.

After scanning through the carbon documentation I found the correct entry:

echo $dt->toIso8601ZuluString();    // 2019-02-01T03:45:27Z

Etymology

In an effort to remember the format better I investigated why it's called a Zulu string, and I found a stack exchange post that explains that the Z indicates UTC Zero hours. In the NATO phonetic alphabet Z is Zulu so that's why it's called Zulu time.

Code example

Here's a laravel example for good measure:

$tz = new DateTimeZone('Europe/Oslo');
echo (new \Illuminate\Support\Carbon('2021-11-15 23:15:35', $tz))
    ->toIso8601ZuluString(); // 2021-11-15T22:15:35Z