java - How to format date for use in a URL as a parameter -


i using api weather forecast until particular date in java.

the requirement passing date url parameter must in "yyyy-mm-dd't'hh:mm:ss" format. input in format user, current system date, , loop until desired date. problem lies in converting input date string date format, incrementing 1 day, , converting string format url parameter.

i using following code giving me incorrect results:

formatter = new simpledateformat("yyyy-mm-dd't'hh:mm:ss"); date date1 = formatter.parse(inputtime); system.out.println(date1); calendar c1 = calendar.getinstance(); c1.settime(date1); c1.add(calendar.day_of_month, 1);  // number of days add inputtime = formatter.format(c1.gettime());  // dt new date system.out.println(c1.gettime()); system.out.println(inputtime); 

inputtime input user. if give "2014-04-12t00:00:00" inputtime, date1 "sun dec 29 00:00:00 pkt 2013", c1.gettime() returns "mon dec 30 00:00:00 pkt 2013" , inputtime becomes "2014-12-364t00:12:00" according above code block.

how can logic error corrected?

you should consider simpledateformat date , time patterns: link

for example, this:

formatter = new simpledateformat("yyyy-mm-dd't'hh:mm:ss"); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -