Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 如何将 DateTime 转换为 VarChar
例子
如何将 SQL 日期时间(例如08/14/2012 1:05:18 PM)转换为 mysql 方式(即 Ymd H:i:s )?
08/14/2012 1:05:18 PM
取决于您要转换它的位置。
要直接在 SQL 中转换:
convert(varchar(23), getdate(), 121)
PHP 使用date和strtotime函数:
date("Y-m-d H:i:s ", strtotime("08/14/2012 1:05:18 PM"));
更改 PHP 中日期的格式,如下所示:
<? $date = date("Y-m-d H:i:s ", strtotime("08/14/2012 1:05:18 PM")); echo $date; ?>
$var = "08/14/2012 1:05:18 PM"; echo date('Y-m-d H:i:s', strtotime($var));