How to convert yyyy-MM-ddTHH: mm: ssZ to yyyy-MM-dd HH: mm: ss?

Paypal returns a timestamp in the following format:

yyyy-MM-ddTHH:mm:ssZ 

And I don’t quite understand what to do with it ...

How can I convert it to yyyy-MM-dd HH: mm: ss using my local timezone in php?

I am tempted to preg_replace mysterious letters, but something tells me that there should be a better way. A difference of 8 hours also appears in my zone, and I'm not sure how to subtract it.

+4
source share
2 answers

Use the DateTime class to do your magic.

 $date = new DateTime('2012-09-09T21:24:34Z'); $date->format('Ym-d'); # read format from date() function 
+10
source

You can use strtotime() to get the UNIX timestamp. From there, you can do whatever you need: DateTime object, date() , etc.

Example with date() :

 echo date('r', strtotime('2012-09-10T10:00:00Z')); 
+4
source

Source: https://habr.com/ru/post/1433258/


All Articles