Java Date to String dateToStringWithPattern(Date date, String pattern)

Here you can find the source of dateToStringWithPattern(Date date, String pattern)

Description

return time value of specified date

License

Open Source License

Parameter

Parameter Description
date the specified date to convert
pattern time format

Return

String value

Declaration

public static String dateToStringWithPattern(Date date, String pattern) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**//ww w . j a va  2 s. com
     * return time value of specified date
     *
     * @param date
     *       the specified date to convert
     * @param pattern
     *       time format
     * @return String value
     */
    public static String dateToStringWithPattern(Date date, String pattern) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
            return simpleDateFormat.format(date);
        } catch (Exception e) {
            return "";
        }
    }
}

Related

  1. dateToStringFormat(Date dt, String format)
  2. dateToStringShort(Date date)
  3. dateToStringTemporalCoverage(Date date)
  4. dateToStringVerbose(Date date)
  5. dateToStringWithFormat(Date dateToString, String dateFormat)
  6. dateToStringWithPattern(Date date, String pattern)
  7. dateToStringWithTime(Date date)
  8. dateToTimeString(Date date)
  9. dateToUTCDate(Date d)