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

longgetLocalTimeFromUTCMillis(long utcMillis)
Convert a UTC timestamp into device local time
return utcMillis - getTimeZoneOffsetInMillis();
longgetLongOfString(String date)
get Long Of String
String dateStr2 = date;
ParsePosition pos2 = new ParsePosition(0);
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd");
Date strtodate2 = formatter2.parse(dateStr2, pos2);
long dateLong2 = strtodate2.getTime();
return dateLong2;
intgetMinute(long dateTimeMillis)
get Minute
SimpleDateFormat format = new SimpleDateFormat("mm");
StringBuilder dateString = new StringBuilder(
        format.format(dateTimeMillis));
return Integer.parseInt(dateString.toString());
intgetMinutesSinceStartOfDay(long milliseconds)
get Minutes Since Start Of Day
Calendar c = Calendar.getInstance();
c.setTimeInMillis(milliseconds);
int hours = c.get(Calendar.HOUR);
int ampm = c.get(Calendar.AM_PM);
if (ampm == Calendar.PM) {
    hours += 12;
int minutes = c.get(Calendar.MINUTE);
...
intgetMonth(long dateTimeMillis)
get Month
SimpleDateFormat format = new SimpleDateFormat("MM");
StringBuilder dateString = new StringBuilder(
        format.format(dateTimeMillis));
return Integer.parseInt(dateString.toString()) - 1;
StringgetNameForDcim(long time)
get Name For Dcim
Date date = new Date(time);
SimpleDateFormat dateFormat = new SimpleDateFormat(
        DATE_TIME_FORMAT_DCIM_FilENAME);
return dateFormat.format(date);
StringgetNameForFile(long time)
get Name For File
Date date = new Date(time);
SimpleDateFormat dateFormat = new SimpleDateFormat(
        DATE_TIME_FORMAT_DCIM_FilENAME);
return dateFormat.format(date);
longgetNumberOfDaysPassed(long date1, long date2)
Returns the number of days passed between two dates.
if (sThenTime == null) {
    sThenTime = new Time();
sThenTime.set(date1);
int day1 = Time.getJulianDay(date1, sThenTime.gmtoff);
sThenTime.set(date2);
int day2 = Time.getJulianDay(date2, sThenTime.gmtoff);
return Math.abs(day2 - day1);
...
StringgetReadableTimeStamp(long timeStamp)
Generate file name from system time in the format "yyyy-MM-dd HH:mm:ss:SSS",
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS", Locale.US)
        .format(new Date(timeStamp));
StringgetReadableTimeUsage(long timeUsageMs)
Format the time usage to string like "1d17h37m3s728ms"
long millisecondsLeft = timeUsageMs % 1000;
if (timeUsageMs == millisecondsLeft) {
    return millisecondsLeft + "ms";
long seconds = timeUsageMs / 1000;
long secondsLeft = seconds % 60;
if (secondsLeft == seconds) {
    return secondsLeft + "s" + millisecondsLeft + "ms";
...