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

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

Description

Convert the date to a String representation using the pattern specified.

License

Open Source License

Parameter

Parameter Description
date The given date.
sPattern The String value that contains the pattern to use (ie. "yyyy/MM/dd hh:mm:ss") during the conversion.

Declaration

public static String dateToString(Date date, String sPattern) 

Method Source Code


//package com.java2s;
import java.text.*;
import java.util.*;

public class Main {
    /**//from  w ww  .j  a va2 s  . co  m
     * Convert the date to a String representation using the pattern specified.
     * @param    date         The given date.
     * @param    sPattern     The String value that contains the pattern to use
     * (ie. "yyyy/MM/dd hh:mm:ss") during the conversion.
     */
    public static String dateToString(Date date, String sPattern) {
        if (date != null) {
            SimpleDateFormat fmtDateHandler = new SimpleDateFormat(sPattern);
            // Perform conversion.
            return fmtDateHandler.format(date);
        } else {
            // Date is null.
            return "";
        }
    }
}

Related

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