如何在PHP中获得2位数的年份?

pat*_*rez 19 php

我希望得到2位数的年份,如15.

使用php date()函数

echo date("Y");
Run Code Online (Sandbox Code Playgroud)

但这会返回全年.

任何帮助都很有帮助.谢谢!

Ric*_*k S 49

将大写'Y'更改为小写'y'

echo date("y");
Run Code Online (Sandbox Code Playgroud)

PHP文档

y   A two digit representation of a year
Run Code Online (Sandbox Code Playgroud)


Pra*_*ari 10

您可以使用PHP的substr()方法获取一年中的最后两位数,如下所示.

$year =  2011;
$year = substr( $year, -2);
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了11作为输出,这是2011年的最后两位数.


Jer*_*nJK 5

http://php.net/manual/en/function.date.php

请参阅此文档.是的date("y").所以小写y而不是Y.