You can do that using the 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/Y H:i');
Pergunta
I received a date string from API respond like this
"2013-07-09T04:58:23.075Z"
How can I parse that string, say to change format to
2013-07-09 [04:58:23]
The time indeed is not based on my local time, I think the .075Z should change something about the time.
Thanks in advance for your help.
Solução
You can do that using the 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/Y H:i');
Outras dicas
try this
$date = '2013-07-09T04:58:23.075Z';
$seconds = strtotime($date);
echo date('Y-m-d [H:i:s]', $seconds);
Hope it helps!
$time = "2013-07-09T04:58:23.075Z";
$exp = explode('T',$time);
echo $exp[0] .' [' .substr($exp[1], 0, -5) . ']';
I'm using it like this.
@Benz
simply add below:
date_default_timezone_set('Australia/Brisbane'); echo date('d/m/Y H:i', strtotime('2013-07-09T04:58:23.075Z'));
were done! Hope this help.