java - SimpleDateFormat API displays wrong Date -
tried formatting few dates using simpledateformat api
string[] dates={"18-01-2015","9-02-2015","21-03-2015"}; for(string s:dates){ simpledateformat format=new simpledateformat("dd-mm-yyyy"); date date=format.parse(s); system.out.println(date); } output:
sun jan 18 00:00:00 ist 2015 fri jan 09 00:00:00 ist 2015 wed jan 21 00:00:00 ist 2015 you notice dates displays jan instead of feb/mar.
you want dd instead of dd when construct simpledateformat. dd means "day of year", not "day of month". every time simpledateformat looks it's doing wrong thing, should consult documentation , check pattern text really, - particularly capitalization.
(there other things can go wrong of course - i've got blog post common ones.)
Comments
Post a Comment