将以下字符串转换为日期

时间:2015-12-24 18:30:56

标签: php

您好我在转换字符串时遇到了问题:

Thu Dec 24 2015 10:39:21 GMT 0000 (GMT)

到PHP的日期。我试过了:

date_default_timezone_set('Europe/London');
$dateTime = strtotime(urldecode($_POST['payment_date'])); //payment_date is the date
$payment_date = date("Y-m-d H:i:s", $dateTime);

但它只是给了我123-28 02:39:21 [2015-12-24 17:26欧洲/伦敦]

1 个答案:

答案 0 :(得分:0)

试试这个:

$string = "Thu Dec 24 2015 10:39:21 GMT";

$date = DateTime::createFromFormat('l M G Y H:i:s O', $string);
var_dump($date);

<强>结果:

object(DateTime)[1]
  public 'date' => string '2015-12-24 10:39:21' (length=19)
  public 'timezone_type' => int 2
  public 'timezone' => string 'GMT' (length=3)