Java SimpleDateFormat format Date to String as "2020.February.25 AD 09:43 AM"

Description

Java SimpleDateFormat format Date to String as "2020.February.25 AD 09:43 AM"

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
  public static void main(String[] args) throws Exception {
    Locale currentLocale = new Locale("en", "US");
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MMMMM.dd GGG hh:mm aaa", currentLocale);
    Date today = new Date();
    String result = formatter.format(today);

    System.out.println("Locale: " + currentLocale.toString());
    System.out.println("Result: " + result);

  }/*from  w  w w.  j ava 2  s  . c om*/
}



PreviousNext

Related