admin管理员组文章数量:1595877
时期类的toTotalMonths()方法用于获取给定时期中的月总数。它返回一个描述它的long值。
用法:
public long toTotalMonths()
参数:此方法不接受任何参数。
返回值:此函数返回long值,该值是此期间内的月总数。
下面是Period.toTotalMonths()方法的实现:
示例1:
// Java code to demonstrate toTotalMonths() method
import java.time.Period;
class GFG {
public static void main(String[] args)
{
// Get the String to be toTotalMonthsd
String period = "P1Y2M21D";
// Parse the String into Period
Period p = Period.parse(period);
System.out.println("Period: " + p);
// Get the total number of months
// using toTotalMonths() method
System.out.println("Total number of Months"
+ " in this Period: "
+ p.toTotalMonths());
}
}
输出:
Period: P1Y2M21D
Total number of Months in this Period: 14
示例2:
// Java code to demonstrate toTotalMonths() method
import java.time.Period;
class GFG {
public static void main(String[] args)
{
// Get the String to be toTotalMonthsd
String period = "-P1Y2M21D";
// Parse the String into Period
Period p = Period.parse(period);
System.out.println("Period: " + p);
// Get the total number of months
// using toTotalMonths() method
System.out.println("Total number of Months"
+ " in this Period: "
+ p.toTotalMonths());
}
}
输出:
Period: P-1Y-2M-21D
Total number of Months in this Period: -14
本文标签: 示例代码totalJavaJavatoTotalMonths
版权声明:本文标题:java的total_Java Period toTotalMonths()用法及代码示例 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728237178a1150554.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论