Java Calendar Time convertTimeToString(Calendar time)

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

Description

Converts time as Calendar in the string format 'hh:mm:ss'.

License

Open Source License

Parameter

Parameter Description
time Calendar of the time to convert

Return

Date object of the given time

Declaration

public static String convertTimeToString(Calendar time) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {
    /**//from  w  w  w.  ja  v  a 2  s . c  o m
     * Converts time as Calendar in the string format 'hh:mm:ss'.
     * 
     * @param time
     *            Calendar of the time to convert
     * @return Date object of the given time
     */
    public static String convertTimeToString(Calendar time) {
        String timeText = "";

        int hour = time.get(Calendar.HOUR_OF_DAY);
        if (hour < 10) {
            timeText += "0";
        }
        timeText += hour + ":";
        int minute = time.get(Calendar.MINUTE);
        if (minute < 10) {
            timeText += "0";
        }
        timeText += minute + ":";
        int second = time.get(Calendar.SECOND);
        if (second < 10) {
            timeText += "0";
        }
        timeText += second;

        return timeText;
    }
}

Related

  1. clearTimeFields(Set c)
  2. clearTimeFromCalendar(Calendar calendar)
  3. compareTimeOnly(Calendar cal1, Calendar cal2)
  4. convertCalendar(final Calendar calendar, final TimeZone timeZone)
  5. convertTimeToLocalTimezone(Long pTime, Calendar pTargetCal)
  6. convertToActiveDirectoryTime(Calendar calendar)
  7. convertToCalendar(long adTimeValue)
  8. convertToTimeStpam(Calendar cal)
  9. convertToTimeZone(Calendar time, TimeZone timeZone)