Here you can find the source of formatDateWithCinderellaTime(Date date)
Parameter | Description |
---|---|
passoutDate | a parameter |
Parameter | Description |
---|---|
FordResourceException | an exception |
public static Timestamp formatDateWithCinderellaTime(Date date)
//package com.java2s; import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.GregorianCalendar; public class Main { /**// w w w .j a va 2 s . c om * Format a date in the following format * 2007-09-27 23:59:00 * @param passoutDate * @return Timestamp * @throws FordResourceException */ public static Timestamp formatDateWithCinderellaTime(Date date) { GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTime(date); gregorianCalendar.set(GregorianCalendar.HOUR_OF_DAY, 23); gregorianCalendar.set(GregorianCalendar.MINUTE, 59); gregorianCalendar.set(GregorianCalendar.SECOND, 0); Date formattedPassoutDate = gregorianCalendar.getTime(); return new Timestamp(formattedPassoutDate.getTime()); } public static Timestamp formatDateWithCinderellaTime(String date) { try { return formatDateWithCinderellaTime(convertToDate(date)); } catch (ParseException pe) { return null; } } /** * Convert a String into a date * @param dateAsString. A String entered that is to be converted * to a string. * @return The java.util.Date version of the string * @throws ParseException if the date can not be converted */ public static Date convertToDate(String dateAsString) throws ParseException { Date utilDate = null; if (isDatePopulated(dateAsString)) { DateFormat df = DateFormat.getInstance(); df.setLenient(false); SimpleDateFormat sf = (SimpleDateFormat) df; sf.applyPattern("dd/MM/yyyy"); utilDate = sf.parse(dateAsString); } return utilDate; } /** * Determine whether an attribute is populated. * @param attribute * @return true if the attribute contains a value. */ public static boolean isDatePopulated(String attribute) { boolean populated = true; if ((attribute == null) || (attribute.trim().length() == 0) || (attribute.equalsIgnoreCase("dd/mm/yy")) || (attribute.equalsIgnoreCase("dd/mm/yyyy"))) { populated = false; } return populated; } }