如何在java中将月份转换成几个月 [英] How to convert months to years-and-months in java
本文介绍了如何在java中将月份转换成几个月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
感谢您的帮助。 p>
解决方案
使用模数%
。
int months = 18;
int years = months / 12; // 1
int remainingMonths = months%12; // 6
Im new to java and I want to convert months to years. For example, If i had 18 months and divided that by 12, I would have 1.5 years but I want it as 1year and 6months.
Thanks for your help.
解决方案
Use the modulus %
.
int months = 18;
int years = months / 12; // 1
int remainingMonths = months % 12; // 6
这篇关于如何在java中将月份转换成几个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文