Java Parse Date parseDateToString(Date date, String pattern)

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

Description

Parses the Date in given format and returns the string representation.

License

BSD License

Parameter

Parameter Description
date the Date to be parsed.
pattern the pattern of the date.

Declaration

public static String parseDateToString(Date date, String pattern) 

Method Source Code

//package com.java2s;
/*L//  www  .j  a  v  a 2s  .c o m
 * Copyright Washington University in St. Louis, SemanticBits, Persistent Systems, Krishagni.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/wustl-common-package/LICENSE.txt for details.
 */

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**
    * Parses the Date in given format and returns the string representation.
    * @param date the Date to be parsed.
    * @param pattern the pattern of the date.
    * @return
    */
    public static String parseDateToString(Date date, String pattern) {
        String d = "";
        //TODO Check for null
        if (date != null) {
            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
            d = dateFormat.format(date);
        }
        return d;
    }
}

Related

  1. parseDateTimeString(final String date)
  2. parseDateTimeString(String dateTime)
  3. parseDateTimeString(String dateTimeString)
  4. parseDateToStr(Date date)
  5. parseDateToString(Date date, String format)
  6. parseDateToString(Date datetime)
  7. parseDateToString(final Date date, final String dateFormat, final String lang)
  8. parseDateValue(String value)
  9. parseDateWithFormat(String date, SimpleDateFormat dateFormat, Date defaultDate)