Format date to string in yyyy-MM-dd format - Android java.util

Android examples for java.util:Date Format

Description

Format date to string in yyyy-MM-dd format

Demo Code

import android.util.Log;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main{

    /**/*  w  w w .java 2 s  . co m*/
     * get the common format time
     * 
     * @param date
     * @return
     */
    public static String getCommonFormat(Date date) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        return f.format(date);
    }

}

Related Tutorials