gpt4 book ai didi

php - 在php中获取正确的日期格式

转载 作者:行者123 更新时间:2023-12-02 03:26:14 27 4
gpt4 key购买 nike

我正在尝试从以下日期格式获取开始日期和结束日期

Wed 19 - Sat 22 June 2013

现在我想要的输出是:-

Startdate = 2013-06-19
Enddate = 2013-06-22

但我得到的输出为:-

Startdate = 1970-01-01
Enddate = 2013-06-22

我尝试过的:-

$old_date = explode('-',$date);
$startdate = date("Y-m-d",strtotime($old_date[0]));
$enddate = date("Y-m-d",strtotime($old_date[1]));

谁能帮帮我吗?

最佳答案

试试这个:

$date = "Wed 19 - Sat 22 June 2013";
$old_date = explode('-',$date);
$date = explode(' ', trim($old_date[1])); //updated line
$startdate = date("Y-m-d",strtotime($old_date[0].' '.$date[2].' '.$date[3]));
$enddate = date("Y-m-d",strtotime($old_date[1]));

关于php - 在php中获取正确的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16476047/

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