get standard date time , like 2018-09-01 14:20:22 - Android java.util

Android examples for java.util:Date Format

Description

get standard date time , like 2018-09-01 14:20:22

Demo Code

import android.text.format.DateUtils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main{

    /**//from ww w.  j a  v a2s .  com
     * get standard date time , like 2018-09-01 14:20:22
     * @return
     */
    public static String getStandardDate(Date date) {

        if (date == null)
            throw new RuntimeException("Given date object is null...");
        SimpleDateFormat format = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        return format.format(date.getTime());
    }

}

Related Tutorials