package com.poi.examples; import java.text.SimpleDateFormat; import java.util.*; public class PrevWeek { public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date dt = prevWeek(new Date(), 7); System.out.println(sdf.format(dt)); } public static Date prevWeek(Date dt, int week) { Calendar cal = Calendar.getInstance(); cal.setTime(dt); cal.add(Calendar.DAY_OF_MONTH, -week * 7 + (9-cal.get(Calendar.DAY_OF_WEEK))); return cal.getTime(); } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/13617.html