- java.time 包類
- java.time - 主頁
- java.time - Clock
- java.time - Duration
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - Period
- java.time - Year
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time 包列舉
- java.time - Month
- java.time 有用資源
- java.time - 討論
java.time.Period.parse() 方法示例
說明
java.time.Period.parse(CharSequence text) 方法從文字字串中獲取一個週期,例如 PnYnMnD 和 PnW。
宣告
以下是對 java.time.Period.parse(CharSequence text) 方法進行的宣告。
public static Period parse(CharSequence text)
public static Period parse(CharSequence text)
引數
text - 要解析的文字,不能為空。
返回值
已解析的週期,不能為空。
異常
DateTimeParseException - 如果無法將文字解析為週期。
示例
package com.tutorialspoint;
import java.time.Period;
public class PeriodDemo {
public static void main(String[] args) {
Period period = Period.parse("P1Y2M3D");
System.out.println("Years: " + period.getYears()
+ ", Months: " + period.getMonths()
+", Days: " + period.getDays());
}
}
實際演示
Years: 1, Months: 2, Days: 3
列印頁面
廣告