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) {
        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:

Livares joins hands with ICT Academy of Kerala