Here you can find the source of dateToString(Date date, String sPattern)
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. |
public static String dateToString(Date date, String sPattern)
//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 ""; } } }