Android Utililty Methods Date Get

List of utility methods to do Date Get


The list of methods to do Date Get are organized into topic(s).


get Current Date Year Month Date Hour Minute Second
Calendar calendar = Calendar.getInstance();
SimpleDateFormat toDateFormat = new SimpleDateFormat(
        "yyyy-MM-dd HH:mm:ss");
return toDateFormat.format(calendar.getTime());
DatecreateDate(final int month, final int day, final int year)
Create a Date object with the specified date.
final Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, month - 1);
cal.set(Calendar.DAY_OF_MONTH, day);
cal.set(Calendar.YEAR, year);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
StringgetDate(int year, int month)
get Date
String date = null;
String a = String.valueOf(year);
String b = String.valueOf(month);
if (month > 9) {
    date = a + b;
} else {
    date = a + "0" + b;
return date;
DategetDateFromString(String dateString)
get Date From String
if (!TextUtils.isEmpty(dateString)) {
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    try {
        return sdf.parse(dateString);
    } catch (ParseException e) {
return null;
get Currently Date
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
return dateFormat.format(new Date());
DategetDate(int day, int month, int year)
get Date
return getCalendar(day, month, year).getTime();