Convert date string from one format to another format using SimpleDateFormat in Java

Description

The following code shows how to convert date string from one format to another format using SimpleDateFormat.

Example


/*  w  w w  . j ava2s.  com*/
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {

  public static void main(String[] args) throws Exception {
    SimpleDateFormat sdfSource = new SimpleDateFormat("dd/MM/yy");
    Date date = sdfSource.parse("12/11/09");
    SimpleDateFormat sdfDestination = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
    System.out.println(sdfDestination.format(date));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone