java 利用 Calendar 获取指定时间

例1:获取今天的0点0分0秒

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,0);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
Date today = calendar.getTime();

例2:获取上个月第一天第一秒

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY,0);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
Date startDate = calendar.getTime();

你可能感兴趣的:(java)