- 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
打印页面
广告