获取当前日期,时间,日子在laravel [英] Getting Current date, time , day in laravel

查看:4158
本文介绍了获取当前日期,时间,日子在laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取当前日期,时间,日期使用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日期时间字符串。



文档:
https://github.com/briannesbitt/Carbon



碳的字符串格式:
http://carbon.nesbot.com / docs /#api-formatting


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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆