(1)根据new Date().getTime()获取从1970年1月1日0点0分到目前的毫秒数计算三天前的时间:
Date dateBy3Days = new Date(new Date().getTime()-3*24*60*60*1000);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String threeDayAgo = sdf.format(dateBy3Days);
threeDayAgo = threeDayAgo + "00:00:00";
(2)Java 1.8后:
String threeDayAgo = LocalDateTime.now().plusDays(-3).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
标签:00,Java,getTime,三天,获取,Date,new,threeDayAgo From: https://www.cnblogs.com/sensenh/p/16623092.html