How to display the name of day for current date in

2020-04-21 01:55发布

I want to print the name of the current date in laravel 5.3. I can get the current date in following ways:

     <?php use Carbon\Carbon;
$carbon=Carbon::now();
              echo $carbon->day;?>

The above code prints 25 but I want it to print Thursday.How should I do that??

标签: php
3条回答
Rolldiameter
2楼-- · 2020-04-21 02:35

Try this

<?php use Carbon\Carbon;
$carbon=Carbon::now();
echo $carbon->format('l');?>
查看更多
对你真心纯属浪费
3楼-- · 2020-04-21 02:45

After Laravel 5.5 you can use now() function to get the current date and time.

In blade file, you can write like this to print name of current day.

{{  now()->format('l') }}

enter image description here

查看更多
女痞
4楼-- · 2020-04-21 02:48

Carbon::now()->format('l') works but I would recommend using

Carbon::now()->formatLocalized('%A')

seeing that this would translate the day string according to the current set locale in case your app is going support internationalization.

查看更多
登录 后发表回答