douhuang7263 2015-01-23 11:44 采纳率: 100%
浏览 3792
已采纳

如何在Laravel中获取当前时间和日期?

我需要利用Laravel得到现在的日期和日期。

我尝试用 $ldate = new DateTime('today');和$ldate = new DateTime('now');,但它总是返回1。

怎样才能得到正确的时间、日期?

  • 写回答

13条回答 默认 最新

  • doulin6761 2015-01-23 11:57
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(12条)

报告相同问题?

悬赏问题

  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题