Period ofDays() 方法在 Java 中
可以使用 Java 中 Period 类的 ofDays() 方法,以给定的天数获取 Period。此方法需要一个参数,即天数,并返回具有给定天数的 Period 对象。
展示这一点的程序如下 −
示例
import java.time.Period;
public class Demo {
public static void main(String[] args) {
int days = 5;
Period p = Period.ofDays(days);
System.out.println("The Period is: " + p);
}
}输出
The Period is: P5D
现在让我们了解上述程序。
使用 ofDays() 方法获取给定天数的 Period,然后打印该 Period。展示该代码片段如下 −
int days = 5;
Period p = Period.ofDays(days);
System.out.println("The Period is: " + p);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP