Android java取得实时上周的时间
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Test { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.add(Calendar.DATE, -7); calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); Date sTime = calendar.getTime(); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); Date eTime = calendar.getTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String s = sdf.format(sTime) + " 00:00:00"; String e = sdf.format(eTime) + " 23:59:59"; System.out.println(s); System.out.println(e); } }