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