laravel need to display only date not time using the carbon class

后端 未结 6 516
陌清茗
陌清茗 2021-02-01 12:40

currently i am using

Carbon::now()

it displays

2015-03-10 23:23:46

but i only need

相关标签:
6条回答
  • This solution will work for you.

    <td>
        {{$message->created_at->todatestring()}}
    </td>
    
    0 讨论(0)
  • 2021-02-01 13:22

    http://carbon.nesbot.com/docs/#api-formatting

    $dt = Carbon::now();
    echo $dt->toDateString(); // Equivalent: echo $dt->format('Y-m-d');
    
    0 讨论(0)
  • 2021-02-01 13:23

    Or you can use this,

    echo Carbon::createFromFormat('Y-m-d H', '1975-05-21 22')->toDateTimeString();
     // 1975-05-21 22:00:00
    

    Example,

    {{ $post->created_at->toDayDateTimeString()}}
    

    Carbon Docs Source Link

    0 讨论(0)
  • 2021-02-01 13:25

    Get Today's Date in Y-m-d formta as given below,

    $dt = Carbon::today()->toDateString(); // Use today to display only date
    

    if you have used $dt = Carbon::today() only, it will return the timestamp also.

    0 讨论(0)
  • 2021-02-01 13:27

    This is correctly:

    $date = Carbon::now();
    echo $date->format('Y-m-d');
    
    0 讨论(0)
  • 2021-02-01 13:33

    Simply use this

    Carbon::today()->toDateString()
    
    0 讨论(0)
提交回复
热议问题