Java Calendar to Time getCalendarStringTime(Calendar c)

Here you can find the source of getCalendarStringTime(Calendar c)

Description

Get time from a Calendar

License

Open Source License

Parameter

Parameter Description
c Calendar

Return

Time String

Declaration

public static String getCalendarStringTime(Calendar c) 

Method Source Code


//package com.java2s;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import java.util.TimeZone;

public class Main {
    /** Get time from a Calendar
     * @param c Calendar/*from   www .jav a2  s. co m*/
     * @return Time String */
    public static String getCalendarStringTime(Calendar c) {
        DateFormat dfm = new SimpleDateFormat("HH:mm:ss");
        return dfm.format(c.getTime());
    }

    /** Get time from a Calendar with specific TimeZone
     * @param c Calendar
     * @param z TimeZone
     * @return Time String */
    public static String getCalendarStringTime(Calendar c, TimeZone z) {
        DateFormat dfm = new SimpleDateFormat("HH:mm:ss");
        dfm.setTimeZone(z);
        return dfm.format(c.getTime());
    }

    /** Converts play time into a String
     * @param t Play time
     * @return String for play time */
    public static String getTime(int t) {
        if (t < 0)
            return "--:--.--";

        return String.format("%02d:%02d.%02d", t / 3600, t / 60 % 60, t % 60 * 5 / 3);
    }
}

Related

  1. calendarToTimeString(Calendar calendar)
  2. getTime(Calendar c)
  3. getTime(Calendar calendar)
  4. getTime(Calendar calendar)
  5. getTime(Calendar pCalendar_)