0

Need a little help. I'm using PHP. Here is a example date: Mon Sep 05 2016 15:30:00 GMT+0800 (China Standard Time)

What i want is display a outpout like this: 2016-09-05 15:30:00

I've tried to convert it using this function: date('Y-m-d h:i:s', strtotime($time));

But the output is: 1970-01-01 08:00:00

Need some advice Thanks.

3 Answers3

1

Just use DateTime():

$time = 'Mon Sep 05 2016 15:30:00 GMT+0800';

$date = new DateTime($time);
echo $date->format('Y-m-d H:i:s');
Grzegorz B.
  • 101
  • 6
0
<?php 
$timezone  = -5; //(GMT -5:00) EST (U.S. & Canada) 
echo gmdate("Y-m-j H:i:s", time() + 3600*($timezone+date("I"))); 
?>

This doc would help more

http://php.net/manual/en/function.gmdate.php

Asuquo12
  • 827
  • 17
  • 26
0

$date=date_create("Mon Sep 05 2016 15:30:00 GMT+0800");

echo date_format($date,"Y/m/d H:i:s");