java - SimpleDateFormat producing wrong date time when parsing "YYYY-MM-dd HH:mm" -
i trying parse string (yyyy-mm-dd hh:mm
) date, getting wrong date expected.
code:
date newdate = null; string datetime = "2013-03-18 08:30"; simpledateformat df = new simpledateformat("yyyy-mm-dd hh:mm", locale.english); df.setlenient(false); try { newdate = df.parse(datetime); } catch (parseexception e) { throw new invalidinputexception("invalid date input."); }
produces: sun dec 30 08:30:00 est 2012 (wrong)
i tried setting lenient off no luck. appreciate help.
update
thanks sudhanshu answer, helped me solve java conversion. when enter returned date above code database getting date correctly time 00:00.
ps.setdate(3, new java.sql.date(app.getdate().gettime()));
yyyy should yyyy-
simpledateformat df = new simpledateformat("yyyy-mm-dd hh:mm", locale.english);
please check documentation simpledateformat here
java 6 : http://docs.oracle.com/javase/6/docs/api/java/text/simpledateformat.html
java 7 : http://docs.oracle.com/javase/7/docs/api/java/text/simpledateformat.html
Comments
Post a Comment