Here you can find the source of toDateString(java.util.Date date, String format)
Parameter | Description |
---|---|
date | The Date |
public static String toDateString(java.util.Date date, String format)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { /**/* w w w . j av a 2s. co m*/ * Makes a date String in the given from a Date * * @param date * The Date * @return A date String in the given format */ public static String toDateString(java.util.Date date, String format) { if (date == null) return ""; SimpleDateFormat dateFormat = null; if (format != null) { dateFormat = new SimpleDateFormat(format); } else { dateFormat = new SimpleDateFormat(); } Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return dateFormat.format(date); } /** * Makes a date String in the format MM/DD/YYYY from a Date * * @param date * The Date * @return A date String in the format MM/DD/YYYY */ public static String toDateString(java.util.Date date) { return toDateString(date, "MM/dd/yyyy"); } }