import java.util.Calendar; import java.util.TimeZone; public class Test { /** * 获取距离系统时间N天后的日期时间信息 * * @author GaoHuanjie */ public String getDateAfterNdays(int days){ Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+8")); calendar.setTimeInMillis(System.currentTimeMillis()-1000L * 60 * 60 * 24 * days); return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH) + " "+ calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND); } public static void main(String[] args) { System.out.println(new Test().getDateAfterNdays(2)); } }
关于时间的操作(Java版)——获取距离系统时间N天后的日期时间信息,布布扣,bubuko.com
时间: 2024-10-18 13:33:36