java获取近几天的日期

最近在写接口的时候老遇见从mysql中获取近几天数据的需求,获取日期这块不是很熟,网上看了很多但是代码量都太大,还是问了下别人,写了三行代码就解决了,不多说 贴代码了

下面是我获取近十天,每天的日期:
 List<String> dayList = new ArrayList<String>();
long start=1559356078000l;
long end=1560133678000l;
do {
dayList.add(new DateTime(start).toString("yyyyMMdd"));
      //plusDays(1)这里是增加一天的意思,后面的getMillis()是获取到毫秒
start = new DateTime(start).plusDays(1).getMillis();
} while (start <= end);

for (String day:dayList) {
System.out.println("近十天的日期"+day);
}
}

猜你喜欢

转载自www.cnblogs.com/shuaidong/p/10996361.html