Convert date string from one format to another format using SimpleDateFormat

 

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

public class Main {
  public static void main(String[] args) throws ParseException {
    String strDate = "30/12/99";

    SimpleDateFormat source = new SimpleDateFormat("dd/MM/yy");

    Date date = source.parse(strDate);

    SimpleDateFormat target = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");

    strDate = target.format(date);
    System.out.println("Converted date is : " + strDate);

  }
}

The output:


Converted date is : 12-30-1999 12:00:00
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.