Java Calendar to Time getTime(Calendar c)

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

Description

get Time

License

Open Source License

Declaration

public static String getTime(Calendar c) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static String getTime(Calendar c) {
        return getDate(c.getTime(), "HH:mm:ss");
    }//from   w  ww. j a v a2 s . c o m

    public static String getDate() {
        return getDate(getCurDate(), "yyyy-MM-dd");
    }

    public static String getDate(Date date, String format) {

        String dtstr = "";
        if (date == null) {
            return dtstr;
        }

        if (format == null || "".equals(format.trim())) {
            format = "yyyy-MM-dd";
        }

        SimpleDateFormat sdf = new SimpleDateFormat(format);
        dtstr = sdf.format(date);
        return (dtstr == null ? "" : dtstr);

    }

    public static String getDate(Date date) {
        return getDate(date, "yyyy-MM-dd");
    }

    public static Date getDate(long time) {

        Calendar c = getCurCalendar();
        c.setTimeInMillis(time);

        return c.getTime();
    }

    public static Date getCurDate() {
        return getCurCalendar().getTime();
    }

    public static Calendar getCurCalendar() {
        return Calendar.getInstance();
    }
}

Related

  1. calendarToTimeString(Calendar calendar)
  2. getCalendarStringTime(Calendar c)
  3. getTime(Calendar calendar)
  4. getTime(Calendar calendar)
  5. getTime(Calendar pCalendar_)
  6. getTimeString(Calendar cal)