0

I have date format (YYYY-MM-DDThh:mm:ss.u):

2017-05-05T18:20:26.000Z

I need to convert it, so it will be without ms (.u) and to add GMT zone at the end of it (YYYY-MM-DDThh:mm:ss+TZD):

2017-05-05T18:20:26+00:00

How to do that? Should I use format() or date_format()?

Thank You!

Qirel
  • 25,449
  • 7
  • 45
  • 62

1 Answers1

2

You could use DateTime::createFromFormat().

$datestring = "2017-05-05T18:20:26.000Z";
$date = DateTime::createFromFormat("YYYY-MM-DDThh:mm:ss.u", $datestring);

Then use format() on $date as you need it.

Qirel
  • 25,449
  • 7
  • 45
  • 62