Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数据可以';t查看为时间格式。它';s返回为int_Php_Laravel - Fatal编程技术网

Php 数据可以';t查看为时间格式。它';s返回为int

Php 数据可以';t查看为时间格式。它';s返回为int,php,laravel,Php,Laravel,我将数据以时间格式存储在数据库中,如“00:02:12”。然后将所有数据相加: foreach($pay_pending as $pending){ $total_pay_pending += strtotime($pending->points_request); } 并退回: return response()->json(['status'=> 'Success', 'Cashout_pending' => $total_pay_pending], 200)

我将数据以时间格式存储在数据库中,如“00:02:12”。然后将所有数据相加:

foreach($pay_pending as $pending){
   $total_pay_pending += strtotime($pending->points_request);
}
并退回:

return response()->json(['status'=> 'Success', 'Cashout_pending' => $total_pay_pending], 200);
它返回一个int值。输出是

{
  "status": "Success",
  "Cashout_pending": 6073229120
}

但我需要它的时间格式。请问,有人能帮我吗?

您可以使用
日期
功能对其进行格式化

return response()->json([
                 'status'=>'Success',
                 'Cashout_pending' => date('d M Y H:i:s',$total_pay_pending) 
                 ], 200);
更改代码:(时间戳的日期格式)


首先将
添加逻辑更改为:

$total_pay_pending = 0;
foreach($pay_pending as $pending){
   $total_pay_pending += strtotime($pending->points_request)-strtotime("00:00:00");
}
然后
return
like-

{
  "status": "Success",
  "Cashout_pending": date("H:i:s",strtotime("00:00:00")+$total_pay_pending);
}
$total_pay_pending = 0;
foreach($pay_pending as $pending){
   $total_pay_pending += strtotime($pending->points_request)-strtotime("00:00:00");
}
{
  "status": "Success",
  "Cashout_pending": date("H:i:s",strtotime("00:00:00")+$total_pay_pending);
}