Parse string in yyyy-MM-dd HH:mm:ss format To Date - Android java.util

Android examples for java.util:Date Parse

Description

Parse string in yyyy-MM-dd HH:mm:ss format To Date

Demo Code

import android.util.Log;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Main{

    public static Date stringToDate(String timeStr) {
        SimpleDateFormat formater = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        try {/*from  w  ww. ja  v  a  2 s  . c om*/
            return formater.parse(timeStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}

Related Tutorials