gpt4 book ai didi

php - 在 php 中转换日期时日期错误

转载 作者:行者123 更新时间:2023-11-29 05:13:15 25 4
gpt4 key购买 nike

我使用下面的代码在 php 中转换日期,但转换后我得到了错误的日期。我在我的数据库表中使用 CURRENT_TIMESTAMP 作为默认值。我从 javascript 传递“日期”变量。

谁能解决这个问题。提前致谢。

$date1=mysql_real_escape_string($data->date);
print_r($date1) // This is one displaying the right date.
$date=strtotime($date1);
$timedatenew=date('Y-m-d H:i:s', $date);
print_r($timedatenew) // This is displaying the date like "1970-01-01 01:00:00".

最佳答案

正如你所说,你的日期格式为 dd/mm/yy 试试这个

  $timedatenew=  date("Y-m-d H:i:s",strtotime(str_replace('/', '-', $date ))));

它将/转换为-

关于php - 在 php 中转换日期时日期错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36602384/

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