Java获取任意一天当前时间

/**
 * 获取某一天时间,传+1是明天,-1昨天,-2前天
**/
public static String getYesterday(int relativelyTime){
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date=new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    date = calendar.getTime();
    String formatTime = sdf.format(date);
    return formatTime;
}

你可能感兴趣的:(后端开发)