<span style="font-size:18px;">
</span>
<span style="font-size:18px;">// 得到 7 15 30天之前的时间</span>
<span style="font-size:18px;">if (time != null && (time.equals("15") || time.equals("7") || time.equals("30"))) {
int timedate = Integer.parseInt(time);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date lastWeekStart = getStart(new Date(), timedate);
String format = sdf.format(lastWeekStart);
String format2 = sdf2.format(new Date());
entity .setBeginregDate(format);
entity.setEndregDate(format2);
}</span>
<span style="font-size:18px;"><span style="white-space:pre"> </span> public static Date getStart(Date date, int sun) {
<span style="white-space:pre"> </span>Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
<span style="white-space:pre"> </span>calendar.setTime(date);
<span style="white-space:pre"> </span>calendar.add(Calendar.DATE, -sun);
<span style="white-space:pre"> </span>return calendar.getTime();
<span style="white-space:pre"> </span>}
</span>
// 相互转换
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date1 = null;
String str1 = "2020-02-14 12:00:00";
try {
date1 = sdf.parse(str1);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
enetity.setBeginValidity(sdf.format(date1));