List of utility methods to do Long to Date Convert
StringBuilder | hrColMin(final long time, final boolean alwaysIncludeHours) hr Col Min final long seconds = time / 1000; final long minutes = (seconds / 60) % 60; final long hours = (seconds / (60 * 60)) % 60; Log.i("DateTimeUtils", "hrColMin hours minutes seconds: " + hours + " : " + minutes + " : " + seconds); final StringBuilder asText = new StringBuilder(); if (alwaysIncludeHours || hours > 0) { if (hours < 10) { ... |
StringBuilder | hrColMinColSec(final long time, final boolean alwaysIncludeHours) hr Col Min Col Sec final long seconds = (time / 1000) % 60; final StringBuilder asText = hrColMin(time, alwaysIncludeHours); asText.append(":"); if (seconds < 10) { asText.append(0); asText.append(seconds); return asText; ... |
boolean | isAtMostNMonthsAgo(long date, int howMany) is At Most N Months Ago Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, -howMany); Date d = new Date(date); return d.after(cal.getTime()); |
boolean | isAtMostNWeeksAgo(long date, int howMany) is At Most N Weeks Ago Calendar cal = Calendar.getInstance(); cal.add(Calendar.WEEK_OF_YEAR, -howMany); Date d = new Date(date); return d.after(cal.getTime()); |
boolean | isYesterday(long date) Checks if the given date is yesterday. final Calendar currentDate = Calendar.getInstance(); currentDate.setTimeInMillis(date); final Calendar yesterdayDate = Calendar.getInstance(); yesterdayDate.add(Calendar.DATE, -1); return yesterdayDate.get(Calendar.YEAR) == currentDate .get(Calendar.YEAR) && yesterdayDate.get(Calendar.DAY_OF_YEAR) == currentDate .get(Calendar.DAY_OF_YEAR); ... |
boolean | isYesterday(long date) Checks if the given date is yesterday. final Calendar currentDate = Calendar.getInstance(); currentDate.setTimeInMillis(date); final Calendar yesterdayDate = Calendar.getInstance(); yesterdayDate.add(Calendar.DATE, -1); return yesterdayDate.get(Calendar.YEAR) == currentDate .get(Calendar.YEAR) && yesterdayDate.get(Calendar.DAY_OF_YEAR) == currentDate .get(Calendar.DAY_OF_YEAR); ... |
String | longTimeToDate(long miliseconds) long Time To Date in format "yyyy-MM-dd HH:mm:ss" Date dt = new Date(miliseconds); return AGO_FULL_DATE_FORMATTER.format(dt); |
String | longTimeToString(int i) long Time To String StringBuilder sb = new StringBuilder(); i = i / 1000; int m = i / 60; int s = i % 60; if (i >= 60) { if (m < 10) { sb.append("0"); sb.append(String.valueOf(m)); ... |
Calendar | longToCalendar(Long time) long To Calendar Calendar c = null; if (time != null) { c = Calendar.getInstance(); c.setTimeInMillis(time); return c; |
String | longToSqlDateFormat(long date) long To Sql Date Format Date d = new Date(date); SimpleDateFormat dateFormat = new SimpleDateFormat(SQL_DATE_FORMAT); return dateFormat.format(d); |