Java Date to String convertDateToString(String mask, Date date)

Here you can find the source of convertDateToString(String mask, Date date)

Description

This method generates a string representation of a date's date/time in the format you specify on input.

License

Open Source License

Parameter

Parameter Description
mask the date pattern the string is in
date a date object

Return

a formatted string representation of the date

Declaration

public static final String convertDateToString(String mask, Date date) 

Method Source Code


//package com.java2s;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    /**/* w w  w . ja v  a  2s. c  om*/
     * This method generates a string representation of a date's date/time
     * in the format you specify on input.
     *
     * @param mask the date pattern the string is in
     * @param date a date object
     * @return a formatted string representation of the date
     */
    public static final String convertDateToString(String mask, Date date) {
        SimpleDateFormat df = null;
        String returnValue = "";

        if (date == null) {
        } else {
            df = new SimpleDateFormat(mask);
            returnValue = df.format(date);
        }

        return returnValue;
    }
}

Related

  1. convertDateToStr(Date d, String format)
  2. convertDateToStr(Date date, String format)
  3. convertDateToString(final Date datum, final boolean withDay)
  4. convertDateToString(java.util.Date dt, String pattern)
  5. convertDateToString(String dateFormat, Date date)
  6. convertDateToURLFormat(final String dateToBeConvert)
  7. convertStringoXSDString(Date date)
  8. convertTimeToString(Date date, String pattern)
  9. convertToString(Date date)