Java Program to parse string date value with default format

Java 8Object Oriented ProgrammingProgramming

For default format, use −

DateFormat.getDateInstance(DateFormat.DEFAULT)

To parse the string date value, use the parse() method

Date dt = DateFormat.getDateInstance(DateFormat.DEFAULT).parse("Nov 19, 2018");

The following is an example −

Example

 Live Demo

import java.text.DateFormat;
import java.util.Date;
public class Demo {
   public static void main(String[] argv) throws Exception {
      // parse date
      Date dt = DateFormat.getDateInstance(DateFormat.DEFAULT).parse("Nov 19, 2018");
      System.out.println("Date: "+dt);
   }
}

Output

Date: Mon Nov 19 00:00:00 UTC 2018
raja
Published on 19-Dec-2018 09:57:00
Advertisements