如何在 PHP 中将年份格式 YY 转换为 YYYY

Ram*_*mal 1 php date

我需要将年份(YY)转换为 YYYY。在这里,我尝试使用datePHP 中的函数,但没有得到预期的结果。

$expiry_year = "30"; //year=2030
echo date('Y',strtotime($expiry_year)); //Result: 1970
echo date('Y',$expiry_year); //Result: 1970
Run Code Online (Sandbox Code Playgroud)

预期结果:2030年

谢谢大家!

Dav*_*ave 5

试试这个,使用 createFromFormat

$date = "30";
$dates = DateTime::createFromFormat('y', $date);
//now to get the outpu:
$arr = $dates->format('Y'); // output : 2030
Run Code Online (Sandbox Code Playgroud)

演示版