parse String To Date by passed in format - Android java.util

Android examples for java.util:Date Parse

Description

parse String To Date by passed in format

Demo Code

import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static Date parseStringToDate(String dateString,
            String dateFormat) {//from   www  .  j  av a  2  s  .  co  m
        SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
        Date dt = null;
        try {
            dt = formatter.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return dt;
    }

}

Related Tutorials