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

Android examples for java.util:Date Format

Description

Format current date in yyyy-MM-dd format

Demo Code

import android.widget.TextView;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String getStringForDate_yyyy_MM_dd() {

        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd",
                Locale.getDefault());
        Date d = new Date(System.currentTimeMillis());
        String dateString = f.format(d);
        return dateString;

    }//from  w  w w  . j a  v  a 2s .c  om

}

Related Tutorials