简体   繁体   中英

Converting time in PHP?

如何使用PHP Sep 27, 2009 2009-09-27 23:58:54将我从数据库2009-09-27 23:58:54提取的时间转换为以下时间。

<?php echo date('M j, Y', strtotime('2009-09-27 23:58:54')); ?>

如果您使用的是MySQL,那么我建议您使用MySQL的date_format()函数,如下所示:

SELECT date_format(date, '%b %e,%Y') AS `formatted_date` FROM `table_name`;

In PHP you can use strtotime or in MySQL you can use UNIX_TIMESTAMP to get the date into a timestamp.

You can then use the date function to format it as you want:

$timestamp = strtotime($myDate);
$dateStr = date('M j, Y', $timestamp);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM