Java Program to parse string date value with default format


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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 27-Jun-2020

82 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements