List of utility methods to do Long to Date Convert
String | stringForTime(long timeMs) string For Time long totalSeconds = timeMs / 1000; long seconds = totalSeconds % 60; long minutes = (totalSeconds / 60) % 60; long hours = totalSeconds / 3600; return String.format("%02d:%02d:%02d", hours, minutes, seconds); |
String | getTimeString(long millis) get Time String StringBuffer buffer = new StringBuffer(); int minutes = (int) ((millis % (1000 * 60 * 60)) / (1000 * 60)); int seconds = (int) (((millis % (1000 * 60 * 60)) % (1000 * 60)) / 1000); buffer.append(String.format("%02d", minutes)).append(":") .append(String.format("%02d", seconds)); return buffer.toString(); |
String | parseTime(long time, String pattern) parse Time Date date = new Date(time); if (isBlank(pattern)) { pattern = "yyyy-MM-dd HH:mm"; SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.getDefault()); return dateFormat.format(date); |
Date | getDateByInt(long va) get Date By Int Date result = new Date(); result.setTime(va); return result; |
String | getDateTimeString(long dateTime) get Date Time String SimpleDateFormat format = new SimpleDateFormat("HH:mm dd/MM/yy"); StringBuilder dateString = new StringBuilder( format.format(dateTime)); return dateString.toString(); |
String | getLabelForEventInTime(long inTime) Returns a label for event happened inTime ms
return android.text.format.DateUtils.getRelativeTimeSpanString( inTime, 0, 0) + " at " + getTimeLabel(inTime + System.currentTimeMillis()); |
String | getTimeDelta(long delta, String dateFormat) Returns time delta from current time with `dateFormat` Calendar current = Calendar.getInstance();
current.setTimeInMillis(current.getTimeInMillis() + delta);
return formatDate(current.getTime(), dateFormat);
|
TimeContainer | timeAgo(long aTime) time Ago TimeContainer result = null; long currentTime = System.currentTimeMillis(); long delta = currentTime - aTime; if (delta > 0) { result = new TimeContainer(); if (delta / (1000 * 60 * 60 * 24 * 30 * 12) > 0) { result.count = (int) (delta / (1000 * 60 * 60 * 24 * 30 * 12)); result.time = Time.YEAR; ... |
boolean | isTomorrow(long lTime) is Tomorrow return isDateDayEqual(lTime, getTimeNextDay(lTime));
|
String | getActivityTime(long startTime, long endTime) get Activity Time long differenceInSeconds = endTime - startTime; if (differenceInSeconds < 60) { return differenceInSeconds + "sec"; } else { long minutes = differenceInSeconds / 60; if (minutes < 60) { return minutes + "min"; } else { ... |