PHP Parse Date From String

I got a date string from the API responding as follows

"2013-07-09T04: 58: 23.075Z"

How can I parse this line, say, change the format to

2013-07-09 [04:58:23]

Time is really not based on my local time, I think the .075Z should change something in time.

Thanks in advance for your help.

+4
source share
4 answers

You can do this using a DateTime object .

 $Date = new DateTime('2013-07-09T04:58:23.075Z'); //create dateTime object $Date->setTimezone(new DateTimeZone('Europe/Amsterdam')); //set the timezone echo $Date->format('d/m/YH:i'); 
+9
source

try it

 $date = '2013-07-09T04:58:23.075Z'; $seconds = strtotime($date); echo date('Ymd [H:i:s]', $seconds); 

Hope this helps!

+1
source
 $time = "2013-07-09T04:58:23.075Z"; $exp = explode('T',$time); echo $exp[0] .' [' .substr($exp[1], 0, -5) . ']'; 

I use it like this.

+1
source

@Benz

just add below:

  date_default_timezone_set ('Australia / Brisbane');

 echo date ('d / m / YH: i', strtotime ('2013-07-09T04: 58: 23.075Z'));

were made! I hope for this help.

-1
source

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


All Articles