Here you can find the source of formatYmd(Date d)
Parameter | Description |
---|---|
d | the date to format |
public static String formatYmd(Date d)
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; public class Main { /**/*from w w w . j a va2 s .c o m*/ * Utility method to format a date in yyyy-MM-dd format * @param d the date to format * @return a String representing the date in the passed format */ public static String formatYmd(Date d) { return formatDate(d, "yyyy-MM-dd", ""); } /** * Utility method to format a date in the given format * @param d the date to format * @return a String representing the date in the passed format */ public static String formatDate(Date d, String format) { return formatDate(d, format, ""); } /** * Utility method to format a date in the given format * @param d the date to format * @param format the DateFormat to use * @param defaultIfNUll the value to return if the passed date is null * @return a String representing the date in the passed format */ public static String formatDate(Date d, String format, String defaultIfNull) { if (d != null) { DateFormat df = new SimpleDateFormat(format); return df.format(d); } return defaultIfNull; } }