当前年份的最后 2 个数字

Mat*_*eau 3 php laravel

我试图在 Laravel 上使用碳来获取本年度的最后 2 个数字。

我在我的控制器中试过这个:

$year = Carbon::now()->year; // ok i got 2017 
Run Code Online (Sandbox Code Playgroud)

我只想得到“17”。我检查了 carbon 的Carbon::createFromFormat函数文档,但我不知道只获取最后 2 个数字的方法。作为 PHP 中 DateTime 中的函数格式。

Odi*_*der 9

试试这个,你会得到 17:

Carbon::now()->format('y')
Run Code Online (Sandbox Code Playgroud)

当您想要格式化碳日期时使用format()

  • 现在,使用最新版本的 Laravel,您可以使用 Carbon 助手并执行 now()->format('y') (2认同)