laravel 以laravel 5的形式自动获取今天的当前日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30723173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get todays current date automatically in form in laravel 5
提问by sabin maharjan
I want to display todays date in date_created field when clicked to create page.
单击以创建页面时,我想在 date_created 字段中显示今天的日期。
{!! Form::open(['route'=>'articles.store'])!!}
<div class="form-group">
<label><b>DATE CREATED</b></label>
{!! Form::text('date_created',null,array('class'=>'form-control date-picker')) !!}
</div>
{!! form::submit('Add',[' class'=>'btn btn-primary form-control'])!!}
{!! Form::close()!!}
采纳答案by chanafdo
You can use
您可以使用
{!! Form::text('date_created',
old('date_created',
Carbon\Carbon::today()->format('Y-m-d')),
['class'=>'form-control date-picker']) !!}
回答by Sougata Bose
回答by Shweta
You can use simple code, as follows:
您可以使用简单的代码,如下所示:
{!! Form::input('date','start_date',date('Y-m-d'),['class' => 'form-control']) !!}
Instead of doing complex code. Aslo you need to add time zone in app.php
file.
而不是做复杂的代码。同样,您需要在app.php
文件中添加时区。
'timezone' => 'Asia/Kolkata',
(For India it is Asia/Kolkata)
(印度是亚洲/加尔各答)
回答by joy
After Laravel 5.5 you can use now() function to get the current date and time.
在 Laravel 5.5 之后,您可以使用 now() 函数来获取当前日期和时间。
In blade file, you can write like this to get date.
在刀片文件中,你可以这样写来获取日期。
{!! Form::text('date_created',
old('date_created',
now()->format('Y-m-d')),
['class'=>'form-control date-picker']) !!}
回答by AH.
Use Carbonfor time and date purpose in Laravel
在 Laravel 中使用Carbon用于时间和日期目的
Carbon is officially supported by Laravel
Carbon 得到 Laravel 的官方支持
Here's how you can print today's date with Carbon.
以下是如何使用 Carbon 打印今天的日期。
{!! Form::open(['route'=>'articles.store'])!!}
<div class="form-group">
<label><b>DATE CREATED</b></label>
{!! Form::text('date_created',Carbon\Carbon::today()->toDateString(),array('class'=>'form-control date-picker')) !!}
</div>
{!! form::submit('Add',[' class'=>'btn btn-primary form-control'])!!}
{!! Form::close()!!}