gpt4 book ai didi

php - strtotime() 期望参数 1 为字符串,时间戳对象

转载 作者:行者123 更新时间:2023-11-29 15:38:40 24 4
gpt4 key购买 nike

我目前正在尝试比较两个日期以确定差异。数据是从mysql服务器拉出的。但是,我不断收到此错误:

strtotime() expects parameter 1 to be string, object given

我尝试过执行一些人们之前已经厌倦的步骤,但它不起作用。

$qa_date= new DateTime ($row["fa_timestamp"]);
$sale_date=new DateTime ($row["time_enter"]);
$timestamp1 = strtotime($qa_date);

$timestamp2 = strtotime($sale_date);

$weekend = array(0, 6);

if(in_array(date("w", $timestamp1), $weekend) || in_array(date("w", $timestamp2), $weekend))
{
return 0;
}
$diff = $timestamp2 - $timestamp1;
$one_day = 60 * 60 * 24; //number of seconds in the day
if($diff < $one_day)
{
return floor($diff / 3600);
}

$days_between = floor($diff / $one_day);
$remove_days = 0;

for($i = 1; $i <= $days_between; $i++)
{
$next_day = $timestamp1 + ($i * $one_day);
if(in_array(date("w", $next_day), $weekend))
{
$remove_days++;
}
}

$diff2= floor(($diff - ($remove_days * $one_day)) / 3600);

最佳答案

DateTime 类中有一个转换方法,因此您可以用它替换 strtotime()

$timestamp1 = $qa_date->getTimestamp();
$timestamp2 = $sale_date->getTimestamp();

关于php - strtotime() 期望参数 1 为字符串,时间戳对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57919106/

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