PHP:获取年份的最后一位数字(例如:2015 == 5)


PHP: Get last digit of year (example: 2015 == 5)

如何将我的函数转换为显示"Y"标签中的最后一个和/或倒数第二个数字?

下面是我的代码:
<?php
$timestamp = time();     //Timestamp from server
$user_time = 1597429549; //Timestamp from database
$time = ($user_time-$timestamp); // Should be around 4 years
echo gmdate("Y m d H i s", $time); //This will output 1974 10 20 19 59 34
?>

如何将此转换为显示时间:

4 10 20 19 59 340004 10 20 19 59 34

而不是:

1974 10 20 19 59 34

使用模数运算符:

2015 % 10 = 5

Substr成功了,谢谢你们给我指出了正确的方向。

    <?php
$timestamp = time();     //Timestamp from server
$user_time = 1597429549; //Timestamp from database
$time = ($user_time-$timestamp); // Should be around 4 years
// This did the trick:
$gmdate = gmdate("y m d H i s", $time);
$rest = substr("$gmdate", -16);
?>
相关文章: