Java DateTimeFormatter format LocalDateTime to String like "02/25/20 08:58:48"

Description

Java DateTimeFormatter format LocalDateTime to String like "02/25/20 08:58:48"

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Main {

  public static void main(String[] args) {

    DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("MM/dd/YY HH:mm:ss");

    LocalDateTime now = LocalDateTime.now();
    String output = now.format(dateFormatter);
    System.out.println(output);/*from   w w w .  jav a 2s  . c  o m*/

  }
}



PreviousNext

Related