Java Program to convert a String to Date


To convert string to date, you can use the parse method.

The following is our date format.

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

Let us convert our string value to date. The value in the parentheses is our string .

Date d = f.parse("13/11/2018");

Example

 Live Demo

import java.text.SimpleDateFormat;
import java.util.Date;
public class Demo {
    public static void main(String[] args) throws Exception {
       SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy");
       Date d = f.parse("13/11/2018");
       System.out.println("Date: "+f.format(d));
    }
}

Output

Date: 13/11/2018

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

163 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements