Android Long to Date Convert hrColMinColSec(final long time, final boolean alwaysIncludeHours)

Here you can find the source of hrColMinColSec(final long time, final boolean alwaysIncludeHours)

Description

hr Col Min Col Sec

Declaration

public static StringBuilder hrColMinColSec(final long time,
            final boolean alwaysIncludeHours) 

Method Source Code

//package com.java2s;

import android.util.Log;

public class Main {
    public static StringBuilder hrColMinColSec(final long time,
            final boolean alwaysIncludeHours) {
        final long seconds = (time / 1000) % 60;

        final StringBuilder asText = hrColMin(time, alwaysIncludeHours);

        asText.append(":");
        if (seconds < 10) {
            asText.append(0);//ww  w  . j  av a2  s  .c o  m
        }
        asText.append(seconds);
        return asText;
    }

    public static StringBuilder hrColMin(final long time,
            final boolean alwaysIncludeHours) {
        final long seconds = time / 1000;
        final long minutes = (seconds / 60) % 60;
        final long hours = (seconds / (60 * 60)) % 60;
        Log.i("DateTimeUtils", "hrColMin  hours  minutes  seconds: "
                + hours + "  : " + minutes + "  : " + seconds);
        final StringBuilder asText = new StringBuilder();
        if (alwaysIncludeHours || hours > 0) {
            if (hours < 10) {
                asText.append(0);
            }
            asText.append(hours);
            asText.append(":");
        }
        if (minutes > 0) {
            if (minutes < 10) {
                asText.append(0);
            }
            asText.append(minutes);
        } else {
            asText.append("00");
        }
        return asText;
    }
}

Related

  1. getUniversalDateStamp(long time)
  2. getUpdateDateStr(long time)
  3. getUpdateTimeStr(long time)
  4. getYear(long dateTimeMillis)
  5. hrColMin(final long time, final boolean alwaysIncludeHours)
  6. isAtMostNMonthsAgo(long date, int howMany)
  7. isAtMostNWeeksAgo(long date, int howMany)
  8. isYesterday(long date)
  9. isYesterday(long date)