How to get Current Timestamp from Carbon in Laravel 5

前端 未结 7 1800
天涯浪人
天涯浪人 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:27

    You can try this if you want date time string:

    use Carbon\Carbon;
    $current_date_time = Carbon::now()->toDateTimeString(); // Produces something like "2019-03-11 12:25:00"
    

    If you want timestamp, you can try:

    use Carbon\Carbon;
    $current_timestamp = Carbon::now()->timestamp; // Produces something like 1552296328
    

    See the official Carbon documentation here.

提交回复
热议问题