Java String to Date toDateString(Date date, String format)

Here you can find the source of toDateString(Date date, String format)

Description

Date converted to string in specified format.

License

Open Source License

Parameter

Parameter Description
date the date
format the format

Return

the string

Declaration

public static String toDateString(Date date, String format) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /** The Constant DD_MMM_YYYY. */
    public static final String YYYYMMDDHHMMSSZ = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";

    /**//from   www .  j  a v a 2  s. co  m
     * Date converted to string in specified format.
     * 
     * @param date
     *            the date
     * @param format
     *            the format
     * @return the string
     */
    public static String toDateString(Date date, String format) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date);
    }

    /**
     * Date converted to string in default (dd-MMM-yyyy) format.
     * 
     * @param date
     *            the date
     * @return the string
     */
    public static String toDateString(Date date) {
        return toDateString(date, YYYYMMDDHHMMSSZ);
    }
}

Related

  1. toDateString(Calendar cal)
  2. toDateString(Date date)
  3. toDateString(Date date)
  4. toDateString(Date date)
  5. toDateString(Date date, String format)
  6. toDateString(Date date, String format)
  7. toDateString(Date date, String formatPattern)
  8. toDateString(Date date, TimeZone timezone)
  9. toDateString(final Date date)