How to convert String to Date in java?

Below code shows how to convert String to Date in java. It converts String Object to java.util.Date

 * Created on 10-2011Copyright(c) All Rights Reserved.
package com.kodehelp.javautil;

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

 * Created by
 * Date: 10/5/11
public class StringToDate {

        public static void main(String[] args) {
            DateFormat df = new SimpleDateFormat("dd/MM/yyyy");

            try {
                Date yesterday = df.parse("04/12/1981");
                System.out.println("Yesterday = " + df.format(yesterday));
            } catch (ParseException e) {

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.