|
发表于 2020-7-13 21:45:01
|
显示全部楼层
package com.ice.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DateUtil {
public static String getStringDateFormat(Date date, String dateformat) {
SimpleDateFormat sf = new SimpleDateFormat(dateformat);
return sf.format(date);
}
public static Date getRMDate(Date nowdate) {
Calendar c=Calendar.getInstance();
c.setTime(nowdate);
System.out.println(DateUtil.getStringDateFormat(c.getTime(), "yyyy-MM-dd"));
c.add(c.MONTH, -1);
System.out.println(DateUtil.getStringDateFormat(c.getTime(), "yyyy-MM-dd"));
return new Date();
}
public static void main(String[] args) throws ParseException {
Date date =new Date();
DateUtil.getRMDate(date);
}
}
|
|