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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -