-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateTimeFormatter.java
More file actions
31 lines (25 loc) · 1.23 KB
/
DateTimeFormatter.java
File metadata and controls
31 lines (25 loc) · 1.23 KB
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
/*
* This class helps us to print and parse date and time in our desired format.
* The format() method of the DateTimeFormatter class is used to format the dates using our desired format.
*/
//* Explanation About The DateTime-Formatter */
import java.time.LocalDateTime;
public class DateTimeFormatter {
public static void main(String[] args) {
LocalDateTime dt = LocalDateTime.now();
System.out.println("The current date is : " + dt);
// ? Print the date as you want to format
java.time.format.DateTimeFormatter dtf = java.time.format.DateTimeFormatter
.ofPattern("dd-MM-yyyy -- E H:m a G q"); // This
// is
// our
// format
// Era Ad - Anno Domini
// q/Q - Quarter of the Year
java.time.format.DateTimeFormatter dtf1 = java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
String myDate = dt.format(dtf1); // Creating date string using an DateFormatter
String myDate1 = dt.format(dtf); // Creating date string using an DateFormatter
System.out.println("This ISO Standard Date Format : " + myDate);
System.out.println("This is user choice data formate : " + myDate1);
}
}