- java.time 軟體包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - 時間戳
- java.time - 日期
- java.time - 日期時間
- java.time - 時間
- java.time - 月日
- java.time - 偏移日期時間
- java.time - 偏移時間
- java.time - 週期
- java.time - 年份
- java.time - 年月
- java.time - 分割槽日期時間
- java.time - 分割槽識別符號
- java.time - 分割槽偏移量
- java.time 軟體包列舉
- java.time - 月份
- java.time 有用資源
- java.time - 探討
java.time.Period.toTotalMonths() 方法示例
說明
java.time.Period.toTotalMonths() 方法獲取此週期內的總月數。
宣告
以下是 java.time.Period.toTotalMonths() 方法的宣告。
public long toTotalMonths()
返回值
週期內總的月數,可以為負數。
示例
以下示例展示了 java.time.Period.toTotalMonths() 方法的用法。
package com.tutorialspoint;
import java.time.Period;
public class PeriodDemo {
public static void main(String[] args) {
Period period = Period.ofYears(2);
System.out.println(period.toTotalMonths());
}
}
我們編譯並執行以上程式,將會得到如下結果 −
24
廣告