php - 在 laravel 中从 UTC 时区将数据显示到 EST 时区
问题描述
我的created_at和updated_at列插入到 UTC 时区。现在我想根据“美国/芝加哥”时区显示数据。我正在使用 Carbon 库来获得结果。
下面是我为从数据库中获取信息而编写的代码。
public function getAllUsers(){
$users = BaseUserModel::
select('id', 'email', 'created_at')
->whereDate(
'created_at',
'=',
Carbon::today('america/chicago')
)
->orderBy('created_at', 'desc')
->limit(5)->get();
return $users;
}
附有 UTC 时间的数据库条目。现在,当我尝试执行查询时,只得到一个输出(2018-10-03 15:27:18)。但我的预期输出应该在“美国/时区”两个日期。
查看 UTC 和美国/芝加哥时区的差异。 https://www.worldtimebuddy.com/
解决方案
您需要使用 UTC 日期/时间进行查询。例如,如果您希望 2018-10-03 0:00:00 CST 到 2018-10-03 23:59:59 CST,则需要使用 2018-10-03 6:00:00 到 2018-10- 进行查询04 5:59:59 取决于时区和夏令时。
推荐阅读
- javascript - 如何从标题标签中提取文本,换行
- 并附加到列表,使用jQuery
- python - HTML订单列表与django模板中的未排序列表混淆
- javascript - Javascript 类属性在一个变量中更改时其他变量中的更改
- java - Spring Boot:根据结果发送响应头
- mongodb - 无法连接到 MongoDB Atlas 集群中的任何服务器,错误消息
- gtk - Gtk.Range 或 Gtk.Scale 中的两个滑块
- python - 将 APScheduler 安装到 Python 3.8
- javascript - Javascript - 获取多维数组的总和
- javascript - quicksight.getSessionEmbedUrl 不是函数
- mysql - 简单的 MySQL JSON 查询需要很长时间才能解决