[英]PHP Carbon get toDay date by formatting date
简单地说,我可以格式化 PHP 日期,例如:
$current_date_time = new DateTime("now");
$user_current_date = $current_date_time->format("Y-m-d");
到今天的日期。 如何在没有日期的情况下使用Carbon
来执行此操作?
$now = Carbon::now();
echo $now; // 2015-11-11 12:38:36
你读过文档吗? 有很多例子如何做
$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
$today = Carbon::today()->toDateString();
您可以像这样格式化输出: Carbon::now()->format('Ym-d');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.