date - My Logic is working fine, but seems too vague.Is there any other easy way to convert "Aug/2016" to "08/2016" in java? -
is there other easy way convert "aug/2016" "08/2016" in java?
my logic working fine, seems vague.
string mydate = "aug/2016"; string str = mydate.split("/")[0]; date date; try { date = new simpledateformat("mmmm").parse(str); calendar cal = calendar.getinstance(); cal.settime(date); system.out.println("##### ----- month in number : " +cal.get(calendar.month+1)); int year = calendar.getinstance().get(calendar.year); int mnth = cal.get(calendar.month) + 1; str = string.valueof(mnth+"/"+year); system.out.println("##### ----- new selected date : " +str); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); }
suggestions please!...
simply use simpledateformat:
string mydate = "aug/2016"; simpledateformat parser = new simpledateformat("mmm/yyyy"); simpledateformat formatter = new simpledateformat("mm/yyyy"); system.out.println(formatter.format(parser.parse(mydate)));
Comments
Post a Comment