我有一个传递给PHP的日期:
$ date = mysql_real_escape_string($ _ POST [" Date"]);
日期显示如下 - Wed Sep 10 2013 00:00:00 GMT-0500(EST) 需要输出 - 2013-09-10
答案 0 :(得分:2)
$dt = new DateTime('Wed Sep 10 2013 00:00:00 GMT-0500 (EST)');
echo $dt->format('Y-m-d');
<强> See it in action 强>
答案 1 :(得分:0)
<?php
// $date = mysql_real_escape_string($_POST["Date"]);
// You should not use mysql_real_escape_string here.
$date = 'Wed Sep 10 2013 00:00:00 GMT-0500 (EST)';
echo date('Y-m-d', strtotime($date));
答案 2 :(得分:0)
$date = mysql_real_escape_string($_POST["Date"]);
echo date('Y-m-d', strtotime($date));