Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert soap time in PHP

Tags:

date

php

I am getting time in the following format as a response of an API call. How I can I convert it to Y-m-d H:i:s I used the following :

$time_other_format = '2013-10-29T08:34:01-0700';

$time = date("Y-m-d H:i:s",strtotime($time_other_format));

This is returning the time, but the time is changed and I think as per the timezone. I have records in DB which are inserted before the convesrion and so retain the original time and to compare it. How can I convert it like that . I mean I need to get the time as 08:34:01 after converting it

like image 981
Happy Coder Avatar asked Nov 28 '13 11:11

Happy Coder


People also ask

How to convert timestamp to date in PHP?

Example of Timestamp to Date in PHP We are converting timestamp to date. echo date( "Y-m-d H:i:s" , 1620790172 ); echo " , "; echo date( "d-m-Y H:i:s" , 1620790172 );

How to fetch current time in PHP?

Answer: Use the PHP date() Function You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s') , date('d/m/y H:i:s') , and so on.

How to insert date and time in PHP?

php $date=strtotime("tomorrow"); echo date("Y-m-d h:i:sa", $date) . "<br>"; $date=strtotime("next Sunday"); echo date("Y-m-d h:i:sa", $date) . "<br>"; $date=strtotime("+3 Months"); echo date("Y-m-d h:i:sa", $date) .


1 Answers

$time_other_format = '2013-10-29T08:34:01-0700';
$dt = new DateTime($time_other_format);
echo $dt->format('Y-m-d H:i:s');

This will echo,

2013-10-29 08:34:01

The DateTime class in PHP is very powerful, and will recognise almost any format you throw at it. It's great for manipulation.

like image 188
Ben Fortune Avatar answered Sep 22 '22 14:09

Ben Fortune