skip to Main Content

I have this format:

How do I use PHP DateTime to format like 2023-01-27T17:37:00.000Z

So far I have

$date = new DateTime();
$string = $date->format('Y-m-dTHH:H:i:s');

but it outputs 2022-11-25UTC0000:00:00:00

What is the correct format

Is there a ressource on the web that would find it for me ? like a helper website.

2

Answers


  1. You can do as follows:

    $date = new DateTime();
    $string = $date->format('Y-m-dTH:i:s.000Z');
    echo $string;
    
    Login or Signup to reply.
  2. You can use the DateTime class to format the date like this:

    $date = new DateTime('2023-01-27T17:37:00.000Z');
    echo $date->format('Y-m-dTH:i:s.uZ'); // Outputs 2023-01-27T17:37:00.000Z
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search