//获取当前时间
Calendar calendar = Calendar.getInstance();
//获取当前年
int year = calendar.get(Calendar.YEAR);
//获取当前月份
int month = calendar.get(Calendar.MONTH) + 1;
//获取当前天
int day = calendar.get(Calendar.DAY_OF_MONTH);
//获取当前小时
int hour = calendar.get(Calendar.HOUR_OF_DAY);
//获取当前分钟
int minute = calendar.get(Calendar.MINUTE);
//获取是这周的第几天 周三 对应数字4
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
//Calendar转Date
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
// 获取前一天date
private Date getBeforeDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, -1);
date = calendar.getTime();
return date;
}
// 获取后一天date
private Date getNextDay(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, +1);
date = calendar.getTime();
return date;
}
网友评论