java时间戳转换String的工具类
public class TimeUtil {
public static List<String> getThisYearMonths(Date yearDate){
List<String> months=new ArrayList<>();
Calendar calendar = Calendar.getInstance();
calendar.setTime(yearDate);
for (int i = 0; i < 12; i++) {
Date date = calendar.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
String dateStr = sdf.format(date);
months.add(dateStr);
calendar.add(Calendar.MONTH,1);
}
return months;
}
public static Date changeToDate(String pattern,String searchDate){
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
Date nowDate;
try {
nowDate = sdf.parse(searchDate);
} catch (ParseException e) {
throw new RtiException("日期转换错误");
}
return nowDate;
}
}