Check out the following code
Code:
public abstract class DateParser
(
/ ** The formatter ** /
private static DateFormat frm = init();
/ ** Initialize the formatter ** /
private static DateFormat init()
( DateFormat frm = new SimpleDateFormat("yyyy-MM -dd HH: mm: ss "); frm.setLenient(false);
return frm;
)
/ ** Convert the string into Date object * @ param String txtDate frm yyyy-mm-dd hh: mm: ss to be converted * @ return Date corresponding (null if input error) ** /
public static Date convert(String txtDate)
(
p = ParsePosition new ParsePosition(0); Date date = frm.parse(txtDate, p);
if( p.getErrorIndex() ! = -1 | | p.getIndex() ! = txtDate.length() ) return null,
return day;
)
)
Bookmarks