在 PHP/MySQL 中使用时间?
mysqlmysqli database
要在 PHP/MySQL 中使用时间,您可以使用 strtotime() 函数。PHP 代码如下 −
$timeValue='8:55 PM'; $changeTimeFormat = date('H:i:s', strtotime($timeValue)); echo("The change Format in 24 Hours="); echo($changeTimeFormat);
PHP代码快照如下 −
这是输出。
这是获取原始时间的 MySQL 查询 −
mysql> SELECT CONCAT('The change Format in 12 Hours in MySQL=',DATE_FORMAT('2019-03-12 20:55:00', '%l:%i %p')) AS OriginalTimeFormat;
以下是输出 −
+------------------------------------------------+ | OriginalTimeFormat | +------------------------------------------------+ | The change Format in 12 Hours in MySQL=8:55 PM | +------------------------------------------------+ 1 row in set (0.00 sec)