Java DateTimeFormatter format LocalDateTime to String like "February 25 2020"

Description

Java DateTimeFormatter format LocalDateTime to String like "February 25 2020"

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

public class Main {

  public static void main(String[] args) {

    DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("MMMM dd yyyy");

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

  }
}



PreviousNext

Related