Java 中的 Period ofMonths() 方法
可以在 Java 中的 Period 類中使用 ofMonths() 方法透過給定的月份數獲取 Period。此方法需要一個引數,即月份數,並返回帶有給定月份數的 Period 物件。
演示這一點的程式如下所示 −
示例
import java.time.Period;
public class Demo {
public static void main(String[] args) {
int months = 11;
Period p = Period.ofMonths(months);
System.out.println("The Period is: " + p);
}
}輸出
The Period is: P11M
現在讓我們瞭解一下上述程式。
使用 ofMonths() 方法獲取帶有給定月份數的 Period,然後對其進行列印。演示這一點的程式碼片段如下所示 −
int months = 11;
Period p = Period.ofMonths(months);
System.out.println("The Period is: " + p);
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP