问题描述
我需要获取当前日期,时间,日期使用laravel我试图回显 $ ldate = new DateTime('today' );
和 $ ldate = new DateTime('now');
但是它总是返回1。
如何获取当前日期,时间,日期在larvel中
Laravel具有附加的 Carbon
依赖。
Carbon :: now()
,包括 Carbon\Carbon
命名空间(如有必要)。
编辑(使用和文档)
说我想检索日期和时间,并将其输出为字符串。
$ mytime = Carbon\Carbon :: now();
echo $ mytime-> toDateTimeString();
这将以通常的格式输出 Ymd H:i:s
,有很多预先创建的格式,您不太可能需要再次使用Carbon来混淆PHP日期时间字符串。
文档:
碳的字符串格式:
I need to get the current date, time, day using laravel
I tried to echo $ldate = new DateTime('today');
and $ldate = new DateTime('now');
But it is returning 1 always.
How can i get the current date, time , day in larvel
Laravel has the Carbon
dependency attached to it.
Carbon::now()
, include the Carbon\Carbon
namespace if necessary.
Edit (usage and docs)
Say I want to retrieve the date and time and output it as a string.
$mytime = Carbon\Carbon::now();
echo $mytime->toDateTimeString();
This will output in the usual format of Y-m-d H:i:s
, there are many pre-created formats and you will unlikely need to mess with PHP date time strings again with Carbon.
Documentation:https://github.com/briannesbitt/Carbon
String formats for Carbon:http://carbon.nesbot.com/docs/#api-formatting
这篇关于获取当前日期,时间,日子在laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!