laravel 需要使用碳类只显示日期而不是时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28962541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:55:03  来源:igfitidea点击:

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

laravellaravel-5laravel-4

提问by Muhammad

currently i am using

目前我正在使用

Carbon::now()

碳::现在()

it displays

它显示

2015-03-10 23:23:46

2015-03-10 23:23:46

but i only need

但我只需要

2015-03-10

2015-03-10

回答by Tjkoopa

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

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

$dt = Carbon::now();
echo $dt->toDateString(); // Equivalent: echo $dt->format('Y-m-d');

回答by Gayashan Perera

Simply use this

简单地使用这个

Carbon::today()->toDateString()

回答by Surahman

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

以 Ymd 格式获取今天的日期,如下所示,

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

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

如果您只使用过$dt = Carbon::today(),它也会返回时间戳。

回答by umar farooq

This solution will work for you.

这个解决方案对你有用。

<td>
    {{$message->created_at->todatestring()}}
</td>

回答by Adrian

This is correctly:

这是正确的:

$date = Carbon::now();
echo $date->format('Y-m-d');

回答by Hunter Eyes

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

碳文档源链接