get Today Time in yyyy-MM-dd format - Android java.util

Android examples for java.util:Day

Description

get Today Time in yyyy-MM-dd format

Demo Code

import android.util.Log;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Main{

    public static long getTodayTime() {
        try {//from   w w w. j ava2 s . c o m
            Date date = new Date();
            SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
            String dateStr = dateformat.format(date);
            return dateformat.parse(dateStr).getTime();
        } catch (Exception e) {
            Log.e("getTodayTime", e.toString());
            return 0;
        }
    }

}

Related Tutorials