Android Utililty Methods Long to Date Convert

List of utility methods to do Long to Date Convert

Description

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

Method

DatetoDateFromTimestamp(long date)
to Date From Timestamp
return new Date(date * 1000);
StringtransMillionToTime(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;
StringtransformDateTime(long t)
transform Date Time
Date date = new Date(t);
SimpleDateFormat dateFormat = new SimpleDateFormat(
        "yyyy-MM-dd HH:mm:ss");
return dateFormat.format(date);
Calendarmillis2cal(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;
StringmillisToString(long l)
millis To String
return String.format("%02d:%02d:%02d", (l / 1000) / 60,
        (l / 1000) % 60, (l / 10) % 100);
StringstdDateFormat(long t)
std Date Format
return formatter.format(t);
StringformatElapsedTime(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);
StringformatSecondsToHHMM(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 += " ";
...
StringgetStringByFormat(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;
StringgetStringByFormat(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;