-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaDateTime.java
More file actions
46 lines (38 loc) · 1.55 KB
/
JavaDateTime.java
File metadata and controls
46 lines (38 loc) · 1.55 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package oops;
/**
*
* @author Sunil Shetty
*/
/*import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
*/
import java.time.*;
import java.time.format.DateTimeFormatter;
public class JavaDateTime {
public static void main(String[]args){
LocalDate myobj = LocalDate.now();
System.out.println(myobj);//in yyyy-mm-dd format
LocalTime t=LocalTime.now();
System.out.println("Before formatting "+t);//in hh-mm-ss format
DateTimeFormatter fo=DateTimeFormatter.ofPattern("ss:mm:hh");
String Formatted = fo.format(t);
System.out.println("After formatting: "+Formatted);
LocalDateTime dt=LocalDateTime.now();
System.out.println(dt);//yyyy-mm-dd-hh-mm-ss
DateTimeFormatter fo1=DateTimeFormatter.ofPattern("dd-mm-yyyy");
String Formatted2 = fo1.format(dt);
System.out.println("After formatting: "+Formatted2);
DateTimeFormatter fo2=DateTimeFormatter.ofPattern("dd-MMM-yyyy");
String Formatted3 = fo2.format(dt);
System.out.println("After formatting: "+Formatted3);
DateTimeFormatter fo3=DateTimeFormatter.ofPattern("e,MMM dd yyyy");
String Formatted4 = fo3.format(dt);
System.out.println("After formatting: "+Formatted4);
}
}