Java String to Date toDateString(java.util.Date date, String format)

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

Description

Makes a date String in the given from a Date

License

Apache License

Parameter

Parameter Description
date The Date

Return

A date String in the given format

Declaration

public static String toDateString(java.util.Date date, String format) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Calendar;

public class Main {
    /**/* w  w  w  . j  av a  2s. co  m*/
     * Makes a date String in the given from a Date
     *
     * @param date
     *            The Date
     * @return A date String in the given format
     */
    public static String toDateString(java.util.Date date, String format) {
        if (date == null)
            return "";
        SimpleDateFormat dateFormat = null;
        if (format != null) {
            dateFormat = new SimpleDateFormat(format);
        } else {
            dateFormat = new SimpleDateFormat();
        }

        Calendar calendar = Calendar.getInstance();

        calendar.setTime(date);
        return dateFormat.format(date);
    }

    /**
     * Makes a date String in the format MM/DD/YYYY from a Date
     *
     * @param date
     *            The Date
     * @return A date String in the format MM/DD/YYYY
     */
    public static String toDateString(java.util.Date date) {
        return toDateString(date, "MM/dd/yyyy");
    }
}

Related

  1. toDateString(Date date, String formatPattern)
  2. toDateString(Date date, TimeZone timezone)
  3. toDateString(final Date date)
  4. toDateString(java.util.Date date)
  5. toDateString(java.util.Date date)
  6. toDateString(java.util.Date date, String spe)
  7. toDateString(long lval)
  8. toDateString(long ms)
  9. toDateString(String fmt, Date date)