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

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

Description

Date converted to a string.

License

Open Source License

Parameter

Parameter Description
date target date
pattern fomate pattern

Return

String

Declaration

public static String dateToString(Date date, String pattern) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

public class Main {
    /**/*  w  w  w  . j  av  a2 s  .c o m*/
     * Date converted to a string.
     * 
     * <pre>
     *  DateUtils.dateToString(new Date(0), "yyyyMMdd") --> 19700101
     * </pre>
     * 
     * @param date target date
     * @param pattern fomate pattern
     * @return String
     */
    public static String dateToString(Date date, String pattern) {
        return getDateFormat(pattern).format(date);
    }

    /**
     * return date format with Locale US.
     * 
     * @param pattern date format pattern.
     * @return DateFormat
     */
    public static DateFormat getDateFormat(String pattern) {
        return new SimpleDateFormat(pattern, Locale.US);
    }
}

Related

  1. dateToString(Date date, String formatStr)
  2. DateToString(Date date, String parttern)
  3. DateToString(Date date, String pattern)
  4. dateToString(Date date, String pattern)
  5. dateToString(Date date, String pattern)
  6. dateToString(Date date, String sPattern)
  7. dateToString(Date date, String strFormat)
  8. datetostring(Date dateInst)
  9. DateToString(Date Expression)