java - Increment Time by one second in a loop -
here simple test: trying increment current timestamp 1 second in loop. output not expect.
public class timetest { public static void main(string[] args) { calendar cal = calendar.getinstance(); (int = 0; < 10; i++) { cal.add(calendar.second, i); system.out.println("updated = " + cal.gettime()); } } }
instead of neat 1 second increments, increments anywhere between 5 seconds 1 second.
updated = mon may 13 15:12:45 pdt 2013 updated = mon may 13 15:12:46 pdt 2013 updated = mon may 13 15:12:48 pdt 2013 updated = mon may 13 15:12:51 pdt 2013 updated = mon may 13 15:12:55 pdt 2013 updated = mon may 13 15:13:00 pdt 2013 updated = mon may 13 15:13:06 pdt 2013 updated = mon may 13 15:13:13 pdt 2013 updated = mon may 13 15:13:21 pdt 2013 updated = mon may 13 15:13:30 pdt 2013
you want add 1
instead of i
on each loop iteration.
cal.add(calendar.second, 1);
Comments
Post a Comment