Calendar
设置固定的时间
@Test
public void lonngTest(){
Calendar calendar = Calendar.getInstance();
System.out.println("直接获取的"+calendar.getTime());
calendar.set(Calendar.HOUR_OF_DAY, 16);
calendar.set(Calendar.MINUTE, 3);
calendar.set(Calendar.SECOND, 21);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(simpleDateFormat.format(calendar.getTime()));
}
获取本周一0点时间
@Test
public void lonngTest1(){
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONDAY),calendar.get(Calendar.DAY_OF_MONTH), 0,0,0 );
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(calendar.getTime());
System.out.println(calendar.get(Calendar.MONTH));
System.out.println(calendar.get(Calendar.MONDAY));
System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(simpleDateFormat.format(calendar.getTime()));
}
获取本月1号0点时间
@Test
public void lonngTest2(){
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK, 1);
calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONDAY),calendar.get(Calendar.DAY_OF_MONTH), 0,0,0 );
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(simpleDateFormat.format(calendar.getTime()));
}
本月末0点时间
@Test
public void lonngTest3(){
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONDAY),calendar.get(Calendar.DAY_OF_MONTH), 0,0,0 );
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(simpleDateFormat.format(calendar.getTime()));
}