forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaDateCurrentEx.java
More file actions
31 lines (22 loc) · 945 Bytes
/
JavaDateCurrentEx.java
File metadata and controls
31 lines (22 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.zetcode;
import java.time.LocalDate;
import java.time.Month;
import java.time.MonthDay;
import java.time.YearMonth;
public class JavaDateCurrentEx {
public static void main(String[] args) {
var date = LocalDate.now();
System.out.println("Current Date: " + date);
var date2 = LocalDate.of(2017, Month.NOVEMBER, 13);
System.out.println("Date from specified date: " + date2);
// current year and month
var yearMo = YearMonth.now();
System.out.println("Current Year and month:" + yearMo);
var specifiedDate = YearMonth.of(2000, Month.NOVEMBER);
System.out.println("Specified Year-Month: " + specifiedDate);
var monthDay = MonthDay.now();
System.out.println("Current month and day: " + monthDay);
var specifiedDate2 = MonthDay.of(Month.NOVEMBER, 11);
System.out.println("Specified Month-Day: " + specifiedDate2);
}
}