How to get Current Timestamp from Carbon in Laravel 5

前端 未结 7 1634
天涯浪人
天涯浪人 2021-02-01 01:05

I want to get current timestamp in laravel 5 and I have done this-

$current_time = Carbon\\Carbon::now()->toDateTimeString();

I am getting e

相关标签:
7条回答
  • 2021-02-01 01:34

    With a \ before a Class declaration you are calling the root namespace:

    $now = \Carbon\Carbon::now()->timestamp;
    

    otherwise it looks for it at the current namespace declared at the beginning of the class. other solution is to use it:

    use Carbon\Carbon
    $now = Carbon::now()->timestamp;
    

    you can even assign it an alias:

    use Carbon\Carbon as Time;
    $now = Time::now()->timestamp;
    

    hope it helps.

    0 讨论(0)
提交回复
热议问题