new Date(new Date().getTime()-25 * 24 * 60 * 60 * 1000) got unexpected date

后端 未结 3 1242
小鲜肉
小鲜肉 2021-01-21 19:24

I would like to generate a list of dates, but found out the date is wrong start from - 25 * 24 * 60 * 60 * 1000

My local date is 2016-07-17. I got

2016-         


        
3条回答
  •  隐瞒了意图╮
    2021-01-21 19:46

    java.time

    Much easier to use minusDays( 1 ) on java.time.LocalDate.

    LocalDate today = LocalDate.now(); // Better to pass the optional `ZoneId`.
    for (int i=0; i<240; i++) {
        LocalDate localDate = today.minusDays( i );
        System.out.println( localDate.toString() );
        …
    }
    

    Back-ported to Android

    Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP.

提交回复
热议问题