Here you can find the source of getDateFromString(String stringDate, String format)
Parameter | Description |
---|---|
stringDate | a parameter |
format | a parameter |
public static Date getDateFromString(String stringDate, String format)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final int EARLIEST_YEAR = 0001; /**/*from w ww .jav a2 s . co m*/ * Purpose: * <br> * getDateFromString<br> * <br> * @param stringDate * @param format * @return<br> */ public static Date getDateFromString(String stringDate, String format) { Date date; SimpleDateFormat sdf = new SimpleDateFormat(format); try { date = sdf.parse(stringDate); } catch (ParseException ex) { date = getNoDate(); } return date; } /** * Purpose: * <br> * getNoDate<br> * <br> * @return<br> */ public static java.util.Date getNoDate() { java.util.Calendar vCalendar = java.util.Calendar.getInstance(); vCalendar.set(java.util.Calendar.DAY_OF_MONTH, 1); vCalendar.set(java.util.Calendar.YEAR, EARLIEST_YEAR); vCalendar.set(java.util.Calendar.MONTH, java.util.Calendar.JANUARY); return killTime(vCalendar).getTime(); } /** * Purpose: * <br> * killTime<br> * <br> * @param aCalendar * @return<br> */ public static java.util.Calendar killTime(java.util.Calendar aCalendar) { if (aCalendar == null) { return null; } java.util.Calendar vCalendar = (java.util.Calendar) aCalendar.clone(); vCalendar.set(java.util.Calendar.MILLISECOND, 0); vCalendar.set(java.util.Calendar.SECOND, 0); vCalendar.set(java.util.Calendar.MINUTE, 0); vCalendar.set(java.util.Calendar.HOUR_OF_DAY, 0); return vCalendar; } /** * Purpose: * <br> * killTime<br> * <br> * @param aDate * @return<br> */ public static java.util.Date killTime(java.util.Date aDate) { if (aDate == null) { return null; } java.util.Calendar vCalendar = java.util.Calendar.getInstance(); vCalendar.setTime(aDate); return killTime(vCalendar).getTime(); } }