Java - Convert String to Date

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

public java.util.Date stringToDate(String datestring) {
        DateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
        java.util.Date date=null;
        try {
            date = df.parse(datestring);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        return date;
To know more about working with strings in different date formats read the complete documentation for the SimpleDateFormat.

Popular posts from this blog

Java XML getElementById returning null, fix using XPath

Sending an Email to Multiple Recipients - Cc: and Bcc:

Store your 450GB data on an A4 size paper: THE RAINBOW TECHNOLOGY