parse string To Time in yyyy-MM-dd HH:mm format - Android java.util

Android examples for java.util:Date Parse

Description

parse string To Time in yyyy-MM-dd HH:mm format

Demo Code

import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.URLEncoder;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.regex.Pattern;

public class Main{

    public static Date parseToTime(String string) {
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date date = null;/*  w w w  .  ja  va  2 s  . c  om*/
        try {
            date = sdf2.parse(string.substring(0, 18));

        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
        return date;
    }

}

Related Tutorials