Java Date Format convertDateToString(Date aDate)

Here you can find the source of convertDateToString(Date aDate)

Description

This method generates a string representation of a date based on the System Property 'dateFormat' in the format you specify on input

License

Apache License

Parameter

Parameter Description
aDate A date to convert

Return

a string representation of the date

Declaration

public static final String convertDateToString(Date aDate) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static String defaultDatePattern = "yyyy-MM-dd";

    /**/*ww w .j ava  2s. c o m*/
     * This method generates a string representation of a date based on the
     * System Property 'dateFormat' in the format you specify on input
     * 
     * @param aDate
     *            A date to convert
     * @return a string representation of the date
     */
    public static final String convertDateToString(Date aDate) {
        return getDateTime(getDatePattern(), aDate);
    }

    /**
     * This method generates a string representation of a date's date/time in
     * the format you specify on input
     * 
     * @param aMask
     *            the date pattern the string is in
     * @param aDate
     *            a date object
     * @return a formatted string representation of the date
     * 
     * @see java.text.SimpleDateFormat
     */
    public static final String getDateTime(String aMask, Date aDate) {
        SimpleDateFormat df = null;
        String returnValue = "";

        df = new SimpleDateFormat(aMask);
        returnValue = df.format(aDate);

        return (returnValue);
    }

    /**
     * Return default datePattern (yyyy-MM-dd)
     * 
     * @return a string representing the date pattern on the UI
     */
    public static synchronized String getDatePattern() {
        return defaultDatePattern;
    }
}

Related

  1. convertDateToHour(Date d)
  2. convertDateToISO8601(Date date)
  3. convertDateToMMDDYYYY(Date date)
  4. convertDateToRpcFormat(Date date)
  5. convertDateToString(Date aDate)
  6. convertDateToString(Date date)
  7. convertDateToString(Date date)
  8. convertDateToString(Date date)
  9. convertDateToString(Date date)