Java Calendar format to String like "Jan 01 2010 12:00:36 PM"

Description

Java Calendar format to String like "Jan 01 2010 12:00:36 PM"


import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {

  public static void main(String[] args) {
    Calendar cal2 = Calendar.getInstance();

    cal2.set(2010, 0, 1, 12, 0);/*from w  w w. j a v  a2  s. co  m*/

    System.out.println(formatDate(cal2));
  }
  public static String formatDate(Calendar cal) {
    SimpleDateFormat simpleFormatter = new SimpleDateFormat(
        "MMM dd yyyy hh:mm:ss aaa");
    return simpleFormatter.format(cal.getTime());
  }
}



PreviousNext

Related