List of utility methods to do Long to Date Convert
Date | toDateFromTimestamp(long date) to Date From Timestamp return new Date(date * 1000); |
String | transMillionToTime(long milliseconds) trans Million To Time int seconds = (int) milliseconds / 1000; int minute = seconds / 60; int second = seconds % 60; String minStr = minute < 10 ? "0" + minute : String.valueOf(minute); String secStr = second < 10 ? "0" + second : String.valueOf(second); String time = minStr + ":" + secStr; return time; |
String | transformDateTime(long t) transform Date Time Date date = new Date(t); SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); return dateFormat.format(date); |
Calendar | millis2cal(long milliseconds, boolean clearTime) milliscal Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(milliseconds); if (clearTime) { cal.clear(Calendar.HOUR); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); return cal; |
String | millisToString(long l) millis To String return String.format("%02d:%02d:%02d", (l / 1000) / 60, (l / 1000) % 60, (l / 10) % 100); |
String | stdDateFormat(long t) std Date Format return formatter.format(t);
|
String | formatElapsedTime(long totalTimeSeconds) format Elapsed Time int seconds = (int) (totalTimeSeconds) % 60; int minutes = (int) ((totalTimeSeconds / (60)) % 60); int hours = (int) ((totalTimeSeconds / (60 * 60)) % 24); return String.format("%dh, %dm, %ds", hours, minutes, seconds); |
String | formatSecondsToHHMM(long seconds) Converts seconds into hours and minutes. long m = (seconds / 60) % 60; long h = (seconds / 60) / 60; String hhmm = ""; if (h > 0) { hhmm += h + "h"; if (m > 0) { hhmm += " "; ... |
String | getStringByFormat(long milliseconds, String format) get String By Format String thisDateTime = null; try { SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat( format); thisDateTime = mSimpleDateFormat.format(milliseconds); } catch (Exception e) { e.printStackTrace(); return thisDateTime; |
String | getStringByFormat(long milliseconds, String format) get String By Format String thisDateTime = null; try { SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat( format); thisDateTime = mSimpleDateFormat.format(milliseconds); } catch (Exception e) { e.printStackTrace(); return thisDateTime; |