Java Date to String dateToString(Date pdttValue, String pstrDateFormat)

Here you can find the source of dateToString(Date pdttValue, String pstrDateFormat)

Description

Date convert to String.

License

Apache License

Return

String representation of the given Date and DateFormat.

Declaration

public static String dateToString(Date pdttValue, String pstrDateFormat) 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**/*from   w w  w  .ja va2  s .co m*/
     * yyyy-MM-dd
     */
    public static final String DATE_FORMAT = "yyyy-MM-dd";

    public static String dateToString(Date pdttValue) {
        return dateToString(pdttValue, null);
    }

    /**
     * Date convert to String.
     * 
     * @return String representation of the given Date and DateFormat.
     */
    public static String dateToString(Date pdttValue, String pstrDateFormat) {
        String pstrDate = null; // return value
        if (pdttValue == null || "".equals(pdttValue)) {
            return null;
        }
        String formatStyle = null;
        if ((pstrDateFormat == null) || (pstrDateFormat.equals(""))) {
            formatStyle = DATE_FORMAT;
        } else {
            formatStyle = pstrDateFormat;
        }
        SimpleDateFormat oFormatter = new SimpleDateFormat(formatStyle);
        pstrDate = oFormatter.format(pdttValue);
        return pstrDate;
    }
}

Related

  1. DateToString(Date Expression)
  2. dateToString(Date fecha)
  3. DateToString(Date fecha, String formato)
  4. dateToString(Date pd_fecha)
  5. dateToString(Date pDate, String pFormat)
  6. DateToString(Date thisdate, Locale locale)
  7. dateToString(final Date date)
  8. dateToString(final Date value, final boolean utc)
  9. dateToString(java.util.Date currdate, String strFormat)