开发者

From month to month and year

For example, I have the month 1开发者_运维问答3 and I want to convert it to 1 year and 1 month with php. 26 - 2 years and 2 months. How to "convert" it?


$totalmonths = 26;
$years = floor($totalmonths/12);
$months = $totalmonths % 12;
echo $years, " year", $years==1?"":"s";
if ($months != 0)
    echo " and ", $months, "month", $months==1?"":"s";


Divide by 12 and take integer part and modulus separately.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜