PHP Carbon 通过格式化日期获取今天的日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33854482/
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-08-25 23:38:29  来源:igfitidea点击:

PHP Carbon get toDay date by formatting date

phpphp-carbon

提问by Robert

Simply I can format PHP date such as:

简单地说,我可以格式化 PHP 日期,例如:

$current_date_time = new DateTime("now");
$user_current_date = $current_date_time->format("Y-m-d");

to get toDay date. how to do this action by using Carbonwithout time in date?

到今天的日期。如何通过使用Carbon无日期时间来执行此操作?

$now = Carbon::now();
echo $now;    // 2015-11-11 12:38:36

回答by Robert

Have you read documentation? There are plenty of examples how to do it

你读过文档吗?有很多例子如何做

$dt = Carbon::now()

var_dump($dt->toDateTimeString() == $dt);          // bool(true) => uses     __toString()
echo $dt->toDateString();                          // 1975-12-25
echo $dt->toFormattedDateString();                 // Dec 25, 1975
echo $dt->toTimeString();                          // 14:15:16
echo $dt->toDateTimeString();                      // 1975-12-25 14:15:16
echo $dt->toDayDateTimeString();                   // Thu, Dec 25, 1975 2:15 PM

// ... of course format() is still available
echo $dt->format('l jS \of F Y h:i:s A');         // Thursday 25th of December 1975 02:15:16 PM

回答by Bhargav Kaklotara

$today = Carbon::today()->toDateString();