【发布时间】:2021-03-27 22:21:49
【问题描述】:
我正在学习 Laravel,但我在控制器上遇到了一些小问题 - 当我使用 DB 时,查询返回没有时区的日期时间,但如果我使用模型,则查询返回完整的日期时间。
public function test($switch)
{
//return "YYYY-MM-DDThh:mm:ss.000000Z"
if ($switch) return Position::select('id','created_at')->orderBy('id')->get();
// return "YYYY-MM-DD hh:mm:ss"
return DB::table('positions')->select('id','created_at')->orderBy('id')->get();
}
为什么?我需要在这两种情况下都想要“YYYY-MM-DDThh:mm:ss.000000Z”吗? 感谢您的解决方案。
谢谢你的建议
【问题讨论】:
标签: laravel datetime date-format date-formatting