假设您在数据库中的记录存储为您提到的 EST,那么您将需要执行以下操作。
// Get the start and end times you want in UTC
$start = Carbon::yesterday('UTC');
$end = Carbon::yesterday('UTC')->endOfDay();
// Convert those times to EST
$start->timezone('EST');
$end->timezone('EST');
// Now query the number of clicks, 'whereBetween' is a great little shortcut
// for querying over a range
Click::whereBetween('created_at', [$start, $end])->count();
请注意,carbon 是一个流畅的 API,因此您可以将其简化为;
$start = Carbon::yesterday('UTC')->timezone('EST');
$end = Carbon::yesterday('UTC')->endOfDay()->timezone('EST');
完全取决于您希望代码如何阅读。
另外,如果未提供, Carbon::now()
and
构建器将使用 php.ini 中指定的默认时区。Carbon::yesterday()