Android Utililty Methods Date Time Get

List of utility methods to do Date Time Get

Description

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

Method

StringgetCurDateTime()
get Cur Date Time
return getCurDateTime(DEFAULTFORMAT);
StringgetCurDateTime(String pattern)
get Cur Date Time
return formatCalendar(Calendar.getInstance(), pattern);
StringgetCurrentDate(String time)
get Current Date
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",
        Locale.CHINA);
return dateFormat.format(Long.valueOf(time));
StringgetCurrentDate(long time)
get Current Date
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd",
        Locale.CHINA);
return dateFormat.format(time);
StringgetDatetime()
get Datetime, "yyyy-MM-dd HH:mm:ss"
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATETIME);
return sdf.format(calendar.getTime());
booleanisNight()
is Night
SimpleDateFormat sdf = new SimpleDateFormat("HH");
int hour = Integer.valueOf(sdf.format(new Date()));
return hour > 18 || hour < 6;
StringgetDateDifference(Date thenDate)
get Date Difference
Calendar now = Calendar.getInstance();
Calendar then = Calendar.getInstance();
now.setTime(new Date());
then.setTime(thenDate);
long nowMs = now.getTimeInMillis();
long thenMs = then.getTimeInMillis();
long diff = nowMs - thenMs;
long diffMinutes = diff / (60 * 1000);
...
StringcurrentTimeLabel()
Returns label for current time.
return formatter.format(new Date(System.currentTimeMillis()));
StringcurrentTimeToString(int format, String delimiter)
current Time To String
return formatDate(new Date(), format, delimiter);
StringgetDate()
get Date
Calendar c = Calendar.getInstance();
int theYear = c.get(Calendar.YEAR) - 1900;
int theMonth = c.get(Calendar.MONTH);
int theDay = c.get(Calendar.DAY_OF_MONTH);
return (new Date(theYear, theMonth, theDay)).toString();