Java Calendar Time getTimeInHHMMSS(Calendar time)

Here you can find the source of getTimeInHHMMSS(Calendar time)

Description

get Time In HHMMSS

License

Open Source License

Declaration

public static String getTimeInHHMMSS(Calendar time) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static String getTimeInHHMMSS(Date time) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(time);/*from   ww  w.  jav a2  s  .c o  m*/
        return getTimeInHHMMSS(cal);

    }

    public static String getTimeInHHMMSS(Calendar time) {
        if (time == null)
            return "HH:MM";
        int h = time.get(Calendar.HOUR_OF_DAY);
        int m = time.get(Calendar.MINUTE);
        StringBuilder sb = new StringBuilder();
        if (h < 10)
            sb.append("0");
        sb.append(h).append(":");

        if (m < 10)
            sb.append("0");
        sb.append(m);

        // sb.append(":");
        // if (s < 10)
        // sb.append("0");
        // sb.append(s);

        return sb.toString();
    }

    public static String toString(int... results) {
        StringBuilder sb = new StringBuilder();
        sb.append('[');
        sb.append(' ');
        for (int i : results)
            sb.append(i).append(',');
        sb.setCharAt(sb.length() - 1, ' ');
        sb.append(']');
        return sb.toString();
    }
}

Related

  1. getTime(Calendar c)
  2. getTime(Calendar c)
  3. getTime(Calendar cal)
  4. getTime(Date date, int CalendarType, int interval)
  5. getTimeFrame(final Calendar calFrom, final Calendar calTo)
  6. getTimeStr(Calendar cal)
  7. getTimeToString(Calendar argCal)
  8. getTimeValue(Calendar cal)
  9. getTimeYYYYMMDD(Calendar calendar)