Java 中 Period() 方法
可以使用 Java 中 Period 类中的 of() 方法,使用给定的天数、月份和年份获取 Period。此方法需要 3 个参数,即天数、月数和年数。此外,它会返回具有给定天数、月数和年份的 Period 对象。
演示此方法的程序如下
示例
import java.time.Period;
public class Demo {
public static void main(String[] args) {
int days = 20;
int months = 11;
int years = 3;
Period p = Period.of(years, months, days);
System.out.println("The Period is: " + p);
}
}输出
The Period is: P3Y11M20D
现在让我们了解一下以上程序。
可以使用 of() 方法获取具有给定天数、月数和年份的 Period,然后对其进行打印。演示此方法的代码片段如下
int days = 20;
int months = 11;
int years = 3;
Period p = Period.of(years, months, days);
System.out.println("The Period is: " + p);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP