PHP中带有AM和PM的字符串的日期格式 [英] Date Formatting in php for string with AM and PM
本文介绍了PHP中带有AM和PM的字符串的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将日期格式从08-28-2018 06:33 PM
更改为2018-07-23 18:33:00
以便将其存储在mysql时间戳中,但无法在PHP中完成
Iam trying to change the date format from 08-28-2018 06:33 PM
to 2018-07-23 18:33:00
in order to store it in mysql timestamp but not able to do it in PHP
推荐答案
使用 DateTime
类:
// Creating from actual format
$date = DateTime::createFromFormat('m-d-Y h:i A', '08-28-2018 06:33 PM');
// Output: 2018-08-28 18:33:00
echo $date->format('Y-m-d H:i:s');
the A
in the format is for uppercase AM/PM (see date parameters).
这篇关于PHP中带有AM和PM的字符串的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文