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

StringtimestampToIso8601Str(long timestamp)
timestamp To Iso Str
return javaDateToIso8601(timestampToDate(timestamp));
StringtimestampToIso8601Str(long timestamp)
timestamp To Iso Str
return javaDateToIso8601(timestampToDate(timestamp));
CalendartoCalendar(long hour)
to Calendar
Calendar calNow = Calendar.getInstance();
Calendar calSet = (Calendar) calNow.clone();
calSet.set(Calendar.HOUR_OF_DAY, calNow.get(Calendar.HOUR_OF_DAY));
calSet.set(Calendar.MINUTE, calNow.get(Calendar.MINUTE));
calSet.set(Calendar.SECOND, calNow.get(Calendar.SECOND) + 3);
calSet.set(Calendar.MILLISECOND, 0);
return calSet;
StringtoDateString(long seconds)
to Date String
return formatter.format(new Date(seconds * 1000L));
StringtoFullDate(long timestamp)
Convert a timestamp from the system timezone to "yyyy-mm-dd HH:mm:ss"
Date date = new Date(timestamp);
return toFullDate(date);
StringtoIso8601(long date, boolean utc)
Formats a date / time according to the ISO 8601 format, optionally forcing to UTC.
if (utc) {
    return DATE_FORMAT_ISO8601_UTC.format(date);
return DATE_FORMAT_ISO8601.format(date);
doubletoJulianDay(long epochMillis)
Calculates the astronomical Julian Day for an instant.
double epochDay = epochMillis / 86400000d;
return epochDay + 2440587.5d;
longtoJulianDayNumber(long epochMillis)
Calculates the astronomical Julian Day Number for an instant.
return (long) Math.floor(toJulianDay(epochMillis) + 0.5d);
StringtoString(Long datetime)
to String
String result = new SimpleDateFormat("yyyyMMddHHmmss")
        .format(new Date(datetime));
return result;
StringtoTimeString(long milliseconds)
to Time String
long secs = milliseconds / 1000;
long mins = secs / 60;
long hours = mins / 60;
secs = secs % 60;
mins = mins % 60;
if (hours > 0) {
    return String.format("%d:%02d:%02d", hours, mins, secs);
return String.format("%d:%02d", mins, secs);