SHARE
TWEET

04.DateTimeFormatter

a guest Feb 17th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top