How to Convert a string to date in JAVA ?

By | April 3, 2012

Hi,

For converting string to a date in JAVA use the following code.

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

public class Main {

  public static void main(String[] args) throws Exception {

    SimpleDateFormat myDateFormat = new SimpleDateFormat("dd/MM/yyyy");

    Date dateToday = dateFormat.parse("25/06/2011");

    System.out.println(myDateFormat.format(dateToday));

  }
}

🙂

Leave a Reply

Your email address will not be published. Required fields are marked *