Parse string value to date by format - Android java.util

Android examples for java.util:Date Parse

Description

Parse string value to date by format

Demo Code

import android.annotation.SuppressLint;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class Main{

    public static Date string2Date(String str, String format) {
        try {/*from  www  .  j a  va  2 s.  com*/
            return new SimpleDateFormat(format).parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return new Date();
    }

}

Related Tutorials