java - Convert Data format using SimpleDateFormat -
i need convert date format new_format date format. want show june 28,2016 ,but showing january irrespective of month number pass. please check missing..
public class dateclass { public static void main(string[] args) { final string old_format = "yyyy-mm-dd"; final string new_format = "mmmm dd,yyyy"; string olddatestring = "2016-06-28"; string newdatestring; simpledateformat sdf = new simpledateformat(old_format); date d; try { d = sdf.parse(olddatestring); sdf.applypattern(new_format); newdatestring = sdf.format(d); system.out.println(""+newdatestring); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
your old_format wrong, should "yyyy-mm-dd". here small m should replaced capital m, since small m represents minutes , m represents month of year, , while parsing using old_format, date getting parsed wrongly.
Comments
Post a Comment