Date and Time

How to convert string to date java

public class SimpleDateFormat extends DateFormat

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date → text), parsing (text → date), and normalization.

public Date parse(String text)

Parses text from a string to produce a Date.

package com.candidjava.datetime;

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

public class StringToDate {
	public static void main(String[] args) {
		try {
			String date="26/09/2020";
			Date convertedDate=new SimpleDateFormat("dd/MM/yyyy").parse(date);
			System.out.println(convertedDate);
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
	}

}

OUTPUT

Sat Sep 26 00:00:00 IST 2020