Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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
Laravel迁移时间戳-独立的数据和时间_Laravel_Eloquent - Fatal编程技术网

Laravel迁移时间戳-独立的数据和时间

Laravel迁移时间戳-独立的数据和时间,laravel,eloquent,Laravel,Eloquent,在我的迁移中,我有一个时间戳,它获取当前数据和发布行的时间 $table->timestamps(); 是否有可能从中获得时间或日期,或者我必须为每个时间使用单独的时间戳 $table->timestamps(); 按照DaveCarruthers的建议,使用默认的timestamps()列 $table->timestamps(); 然后,在需要时分开日期和时间: $table->timestamps(); $model->created_at->toDateS

在我的迁移中,我有一个时间戳,它获取当前数据和发布行的时间

$table->timestamps();
是否有可能从中获得时间或日期,或者我必须为每个时间使用单独的时间戳

$table->timestamps();

按照DaveCarruthers的建议,使用默认的
timestamps()

$table->timestamps();
然后,在需要时分开日期和时间:

$table->timestamps();
$model->created_at->toDateString();
$model->created_at->toTimeString();

只需按默认方式存储并按需要格式化即可,Laravel提供了日期时间的碳元素,从时间戳创建碳元素对象,并使用内置函数拆分所需内容。准确地说,
created_at->format('H:i:s')在你自己弄明白后删除帖子。