java判断当前是星期几&日期格式化&获取前一天日期

1.判断当前日期是星期几:

Date date = new Date();

Calendar cal = Calendar.getInstance();

cal.setTime(date);

int week = cal.get(Calendar.DAY_OF_WEEK) - 1;//0是星期天,6是星期六



2.格式化日期格式:

Date date = new Date();

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

String today = format.format(date);



3.跳转到指定日期:

Date date = new Date();

Calendar cal = Calendar.getInstance();

cal.setTime(date);

cal.add(Calendar.DAY_OF_YEAR, -1);

date = cal.getTime();

yesterday = format.format(date);

你可能感兴趣的:(java判断当前是星期几&日期格式化&获取前一天日期)