gpt4 book ai didi

php - 如何将日期从一种格式转换为另一种格式?

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:59 24 4
gpt4 key购买 nike

我在 Excel 工作表 03-Dec-10 中有这种格式的日期。所以它在将它插入数据库时​​不兼容。如何将日期转换为可接受的格式?

最佳答案

$input = '03-Dec-10';
$date = DateTime::createFromFormat('d-M-y', $input);
echo $date->format('Ymd'); // or possibly 'Y-m-d'

这将输出 20101203,这大概是您想要的。如果这不是您想要的,请查看 here .

你也可以反过来做:

$input = '20101203';
$date = DateTime::createFromFormat('Ymd', $input);
echo $date->format('d-M-y');

关于php - 如何将日期从一种格式转换为另一种格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5504642/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com