Advertisement
Guest User

04.DateTimeFormatter

a guest
Feb 17th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import java.time.LocalDateTime;
  2. import java.time.format.DateTimeFormatter;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. LocalDateTime myDate = LocalDateTime.now();
  7. System.out.println("Before formatting : " + myDate);
  8.  
  9. DateTimeFormatter myFormatDate = DateTimeFormatter.ofPattern("dd-MM-yyyy");
  10. String myFormattedDate = myDate.format(myFormatDate);
  11. System.out.println("After formatting : " + myFormattedDate);
  12.  
  13. DateTimeFormatter anotherFormatDate = DateTimeFormatter.ofPattern("HH-mm-ss");
  14. String anotherFormatToMyDate = myDate.format(anotherFormatDate);
  15. System.out.println("After another format date : " + anotherFormatToMyDate);
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement