java - adding/removing days from date code fix needed -
i have code here:
public static string addremovedays(string date, int days) throws parseexception { simpledateformat k = new simpledateformat("yyyymmdd"); date d = k.parse(date); d = new date(d.gettime() + days*86400000); string time = k.format(d); return time; } it take string formed "yyyymmdd", , adds int days it. should work days negative - substract days date. when it's math, returns string formated "yyyymmdd".
at least should do. works small numbers, if try add (or remove), example, year (365 or -365), returns wierd dates.
what's problem? should completley way?
d = new date(d.gettime() + days*86400000); if multiply 86400000 365 integer cant hold it. change 86400000 long
d = new date(d.gettime() + days*86400000l); and fine.
Comments
Post a Comment