Java Data Type How to - Format date as form of Jun 22, 2015 2:08 PM








Question

We would like to know how to format date as form of Jun 22, 2015 2:08 PM.

Answer

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
//w w  w .java  2s . c o m
public class Main {

  public static void main(String[] args) {
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter
        .ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT);
    System.out.println(dateTimeFormatter.format(LocalDateTime.now())); 

  }
}

The code above generates the following result.