Java Data Type How to - Convert date and time format


We would like to know how to convert date and time format.


import java.text.SimpleDateFormat;
import java.util.Date;
/*from w  w w.java2 s  .c  om*/
public class Main {
  public static void main(String[] args) throws Exception {
    SimpleDateFormat sd = new SimpleDateFormat();
    String dateString = "2015-01-02 14:59:27.953";
    sd.applyPattern("yyyy-MM-dd HH:mm:ss.SSS");
    Date date = sd.parse(dateString);
    sd.applyPattern("MM/dd/yyyy HH:mm a");

The code above generates the following result.