get Current Date as string in yyyy-MM-dd format - Android java.util

Android examples for java.util:Date Format

Description

get Current Date as string in yyyy-MM-dd format

Demo Code

import android.support.annotation.Nullable;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main{

    public static String getCurrentDate() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        long now = System.currentTimeMillis();
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(now);/*w w  w  . j  av a2 s .co m*/
        String date = formatter.format(calendar.getTime());
        return date;
    }

}

Related Tutorials