Free Data Structures and Algorithms Course

Subscribe below and get all best seller courses for free !!!


Subscribe to all free courses

How to convert String object to a Date object in Java program ?.

Program to demonstrate conversion of String object to Date object in Java

package com.hubberspot.examples;

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

public class StringToDateConversion {
   public static void main(String[] args) {
      String dateFormatInString = "dd/MM/yyyy";
      DateFormat df = new SimpleDateFormat(dateFormatInString);
      try {
 Date date = df.parse("20/08/2012");
 System.out.println("Converted String to Date: "
         + df.format(date));
      catch(ParseException pe) {


Output of the program :

© 2021 Learn Java by Examples Template by Hubberspot