Returns a string representation of the whole datetime object. - Java java.util

Java examples for java.util:Time

Description

Returns a string representation of the whole datetime object.

Demo Code


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

public class Main{
    public static void main(String[] argv) throws Exception{
        Calendar calendar = Calendar.getInstance();
        System.out.println(toString(calendar));
    }/*  w  w w .j a  va 2 s . co m*/
    /** Format of the date and time part. */
    public static final String FORMAT_DATE_TIME = "%1$tF %1$tT";
    /**
     * Returns a string representation of the whole datetime object.
     *
     * @param calendar
     *            the datetime object to considered
     * @return this datetime object as String
     */
    public static String toString(Calendar calendar) {
        return String.format(CalendarUtil.FORMAT_DATE_TIME, calendar);
    }
}

Related Tutorials