Parse string in yyyy-MM-dd format to date - Android java.util

Android examples for java.util:Date Parse

Description

Parse string in yyyy-MM-dd format to date

Demo Code

import android.text.format.Time;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main{

    public static Date getDateByStr2(String dd) {

        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
        Date date;//from   w  w  w.  j  ava2s .co  m
        try {
            date = sd.parse(dd);
        } catch (ParseException e) {
            date = null;
            e.printStackTrace();
        }
        return date;
    }

}

Related Tutorials