我试图在 Laravel 上使用碳来获取本年度的最后 2 个数字。
我在我的控制器中试过这个:
$year = Carbon::now()->year; // ok i got 2017
Run Code Online (Sandbox Code Playgroud)
我只想得到“17”。我检查了 carbon 的Carbon::createFromFormat函数文档,但我不知道只获取最后 2 个数字的方法。作为 PHP 中 DateTime 中的函数格式。
试试这个,你会得到 17:
Carbon::now()->format('y')
Run Code Online (Sandbox Code Playgroud)
当您想要格式化碳日期时使用format()