Java中的LocalDateTime getDayOfYear()方法
可以使用getDayOfYear()Java中LocalDateTime类中的方法来获取特定LocalDateTime的日期。此方法不需要任何参数,它会返回一年中的日期,该日期可以在1到365之间,对于leap年也可以是366。
演示此的程序如下所示-
示例
import java.time.*;
public class Demo {
public static void main(String[] args) {
LocalDateTime ldt = LocalDateTime.parse("2019-02-18T11:30:15");
System.out.println("The LocalDateTime is: " + ldt);
System.out.println("The day of the year is: " + ldt.getDayOfYear());
}
}输出结果
The LocalDateTime is: 2019-02-18T11:30:15 The day of the year is: 49
现在让我们了解上面的程序。
首先显示LocalDateTime。然后使用该getDayOfYear()方法显示LocalDateTime的一年中的一天。演示这的代码片段如下-
LocalDateTime ldt = LocalDateTime.parse("2019-02-18T11:30:15");
System.out.println("The LocalDateTime is: " + ldt);
System.out.println("The day of the year is: " + ldt.getDayOfYear());热门推荐
10 广西考试祝福语结婚简短
11 猪年祝福语简短小孩
12 元旦祝福语送长辈简短
13 恭喜二宝祝福语简短
14 祝福语暖心话简短
15 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特