How to generate date for next 14 days in java? -
public class datefornext14days { public static void main(string[] args) { final calendar c = calendar.getinstance(); int day=c.get(calendar.day_of_month); (int = 1; i<=14; i++) { system.out.println(day); c.add(c.get(calendar.day_of_month), 1); } } }
while executing code got following error:-
exception in thread "main" java.lang.illegalargumentexception @ java.util.gregoriancalendar.add(unknown source) @ todaydate.main(todaydate.java:28)
i wanted output - start current day , iterate next 14 days.
remove c.get(
. first parameter of add constant unit
c.add(calendar.day_of_month, 1);
for more informations see javadoc.
and output day in following way:
system.out.println(c.get(calendar.day_of_month));
so code must like:
public static void main(string[] args) { final calendar c = calendar.getinstance(); (int = 1; <= 14; i++) { system.out.println(c.get(calendar.day_of_month)); c.add(calendar.day_of_month, 1); } }
Comments
Post a Comment