Here you can find the source of parseDate(Date date)
Parameter | Description |
---|---|
date | Date object |
public static String parseDate(Date date)
//package com.java2s; import java.util.*; import java.text.*; public class Main { /**//w ww. j a v a 2 s.c o m * Default Date format */ public static final String DATE_FORMAT = "dd-MM-yyyy"; /** * Return a Date for the DATE_FORMAT format string * * @param dateStr Date format string * * @return Java Date object if the input is valid, else null */ public static Date parseDate(String dateStr) { // Check input if (dateStr == null) { return null; } // Create the formatter object SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); // Do not parse the string if it do not adhere to the format given formatter.setLenient(false); // Parse ParsePosition pos = new ParsePosition(0); Date date = formatter.parse(dateStr, pos); // Return return date; } /** * Return a String for the given java.util.Date as per DATE_FORMAT * * @param date Date object * * @return String for the given java.util.Date as per DATE_FORMAT, null in * case of error */ public static String parseDate(Date date) { // Check input if (date == null) { return null; } // Create the formatter object SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); // Do not parse the string if it do not adhere to the format given formatter.setLenient(false); // Parse return formatter.format(date); } }