Here you can find the source of convertDateToString(Date aDate)
Parameter | Description |
---|---|
aDate | A date to convert |
public static String convertDateToString(Date aDate)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**//from ww w. j a v a2s . c om * This method generates a string representation of a date based on the * System Property 'dateFormat' in the format you specify on input * * @param aDate * A date to convert * @return a string representation of the date */ public static String convertDateToString(Date aDate) { return getDateTime(getDatePattern(), aDate); } public static String convertDateToString(String aMask, Date aDate) { SimpleDateFormat df = null; String returnValue = ""; if (aDate != null) { df = new SimpleDateFormat(aMask); returnValue = df.format(aDate); } return (returnValue); } public static String getDateTime(java.util.Date date) { return format(date, "yyyy-MM-dd HH:mm:ss"); } /** * This method generates a string representation of a date's date/time in * the format you specify on input * * @param aMask * the date pattern the string is in * @param aDate * a date object * @return a formatted string representation of the date * * @see java.text.SimpleDateFormat */ public static String getDateTime(String aMask, Date aDate) { SimpleDateFormat df = null; String returnValue = ""; if (aDate != null) { df = new SimpleDateFormat(aMask); returnValue = df.format(aDate); } return (returnValue); } /** * Return default datePattern (MM/dd/yyyy) * * @return a string representing the date pattern on the UI */ public static String getDatePattern() { return "yyyy-MM-dd"; } public static String format(java.util.Date date, String format) { String result = ""; try { if (date != null) { java.text.DateFormat df = new java.text.SimpleDateFormat(format); result = df.format(date); } } catch (Exception e) { } return result; } public static String format(java.util.Date date) { return format(date, "yyyy/MM/dd"); } }