Here you can find the source of formatDate(Date unformattedDate, String format)
Parameter | Description |
---|---|
unformattedDate | the date to be formated |
format | the format to be formated like dd/mm/yyyy or mm/dd/yy etc refer SimpleDateFormat for supported format. |
public static String formatDate(Date unformattedDate, String format)
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**// ww w . j a v a 2 s . c o m * Formats a give date with the supplied format * @param unformattedDate the date to be formated * @param format the format to be formated like dd/mm/yyyy or mm/dd/yy etc * refer SimpleDateFormat for supported format. * @return */ public static String formatDate(Date unformattedDate, String format) { String formattedDate = ""; try { DateFormat df = DateFormat.getInstance(); SimpleDateFormat sf = (SimpleDateFormat) df; sf.applyPattern(format); formattedDate = df.format(unformattedDate); } catch (RuntimeException e) { //LOG.log(Level.WARNING, "Error Formatting Date:" + unformattedDate); } return formattedDate; } }