java - Calendar class: set to ten days from now -


i have following 2 methods:

private long gettimeinmilliseconds()     {         calendar c = calendar.getinstance();           if(c.get(calendar.day_of_month) == 21)           {             c.set(calendar.month, calendar.month + 1 );             c.set(calendar.day_of_month, 1);         }         else             c.set(calendar.day_of_month, calendar.day_of_month + 10);          if(c.get(calendar.month) > 11)             c.set(calendar.month, 0);          return c.gettimeinmillis();     }  public static void remainingtime(l2pcinstance player)     {         long = system.currenttimemillis();         long = player.getexpboosttime();          long time = - now;          int hours = (int) (time / 3600000);          player.sendmessage(hours+ " hours remaining until exp boost period ends");     } 

i want gettimeinmillisseconds() return time 10 days later. want remainingtime() show how many days (in hours) remain.

with code above, shows 4 days remaining , not 10.

can help?

you making mistake in set() method.

it should be

c.set(calendar.day_of_month, c.get(calendar.day_of_month) + 10); 

however, approach far being best. 1 suggested in answer (adding 10 * 24 * 60 * 60 * 1000 milliseconds current time) far better imho.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -