Here is my code snippet. I need to subtract days from a specific date, but I do not get the expected results:
public class TestingDates { public static void main(String[] args) { Date toDate=new Date(); Date fromDate=new Date(); for (int i = 0; i < 30; i++) { fromDate.setTime(toDate.getTime() - i * 24 * 60 * 60 * 1000); System.out.println(fromDate); } } }
And I am confused with this result
displayed here
Fri Sep 13 12:24:50 IST 2013 Thu Sep 12 12:24:50 IST 2013 Wed Sep 11 12:24:50 IST 2013 Tue Sep 10 12:24:50 IST 2013 Mon Sep 09 12:24:50 IST 2013 Sun Sep 08 12:24:50 IST 2013 Sat Sep 07 12:24:50 IST 2013 Fri Sep 06 12:24:50 IST 2013 Thu Sep 05 12:24:50 IST 2013 Wed Sep 04 12:24:50 IST 2013 Tue Sep 03 12:24:50 IST 2013 Mon Sep 02 12:24:50 IST 2013 Sun Sep 01 12:24:50 IST 2013 Sat Aug 31 12:24:50 IST 2013 Fri Aug 30 12:24:50 IST 2013 Thu Aug 29 12:24:50 IST 2013 Wed Aug 28 12:24:50 IST 2013 Tue Aug 27 12:24:50 IST 2013 Mon Aug 26 12:24:50 IST 2013 Sun Aug 25 12:24:50 IST 2013 Sat Aug 24 12:24:50 IST 2013 Fri Aug 23 12:24:50 IST 2013 Thu Aug 22 12:24:50 IST 2013 Wed Aug 21 12:24:50 IST 2013 Tue Aug 20 12:24:50 IST 2013 Tue Oct 08 05:27:38 IST 2013 Mon Oct 07 05:27:38 IST 2013 Sun Oct 06 05:27:38 IST 2013 Sat Oct 05 05:27:38 IST 2013 Fri Oct 04 05:27:38 IST 2013
please help me deal with this problem.
source share