Returns a string representation of the date part of this datetime object. - Java java.util

Java examples for java.util:Time

Description

Returns a string representation of the date part of this 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{
        Date date = new Date();
        System.out.println(toStringDateOnly(date));
    }/*ww w . ja  v  a  2s. c o m*/
    /** Format of the date part. */
    public static final String FORMAT_DATE_ONLY = "%1$tF";
    /**
     * Returns a string representation of the date part of this datetime object.
     *
     * @param date
     *            the datetime object to considered
     * @return the date part of this datetime object as String
     */
    @Deprecated
    public static String toStringDateOnly(Date date) {
        return String.format(CalendarUtil.FORMAT_DATE_ONLY, date);
    }
    /**
     * Returns a string representation of the date part of this datetime object.
     *
     * @param calendar
     *            the datetime object to considered
     * @return the date part of this datetime object as String
     */
    public static String toStringDateOnly(Calendar calendar) {
        return String.format(CalendarUtil.FORMAT_DATE_ONLY, calendar);
    }
}

Related Tutorials