[好,我有一个问题,希望您能为我提供帮助,事实是,我必须从数据库中获取一些时间戳并将其添加一天,好吧,我使用了碳添加日(),但是由于carbon不想比较我的时间戳,那么我不得不转换为字符串,在解析时我可以将它们同化为carbon,但是在此过程中,我的日期更改了,日期是正常的,但由于某种原因的时间加起来小时,这完全改变了我寻找的结果,我该如何解决?我通过命令:
<?php
namespace App\Console\Commands;
use App\p;
use App\Pe;
use App\Mail\SendMailable;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use Carbon\Carbon;
class LimpiarDiario extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'Task:LD';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Tasks';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$datedi = p::select('p.Date', 'p.coddate')
->where('p.cod_paperiod', '=', 1)
->get();
foreach ($datedi as $dateda)
{
$cod = $dateda->coddate;
$now = Carbon::now();
$dateli = $dateda->Date;
$dateinter = strtotime($dateli);
$datecar = Carbon::Parse($dateinter);
$datetrans = $datecar->addDay();
$datenue= $datetrans->toDateTimeString();
if ($dateda->Date < $now)
{
$prueba= p::where('coddate','=', $cod)
->update(['Date' => $datenue]);
}
}
}
为了显示问题,我的日期为:{"Date":"2020-06-12 16:00:00.000000","coddate":53}
然后它成为dateli,其值为:2020-06-12 16:00:00.000000
再次成为dateinter,其值为:1591992000
最后通过可变日期车变成碳:"2020-06-13T20:00:00.000000Z"
如您所见,由于某种原因,它现在比原始时间增加了4个小时,所以当我注册结果时,它为我节省了日期:2020-06-13 20:00:00
[所需的结果应为:2020-06-12 16:00:00
因此,如前所述,我必须寻求帮助才能知道如何在解析中设置时间,或者如何在不更改小时的情况下将时间戳转换为时间戳。
PHP生成的时间基于服务器配置中的时间,但是javascript生成的时间基于您当前的设备。