开始
1.获取web-inf下路径:
String classPath = BaseDataProc.class.getClassLoader().getResource(".").getPath();
String path = classPath.substring(0, classPath.indexOf("WEB-INF"));
2.日期转换
/**
* 单个时间格式化(dateStr -> Date)
*
* @param time
* @param sdsStr
* @return
*/
public static Date strFormatToTime(String dataStr, String format) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
LocalDateTime time = LocalDateTime.parse(dataStr, formatter);
ZoneId zoneId = ZoneId.systemDefault();
Instant instant = time.atZone(zoneId).toInstant();
Date date = Date.from(instant);
return date;
}
/**
* 单个时间格式化(Date -> dateStr)
*
* @param time
* @param sdsStr
* @return
*/
public static String dateFormatMD(Date time, String sdsStr) {
if (time == null) {
return "";
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(sdsStr);
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = LocalDateTime.ofInstant(time.toInstant(), zoneId);
String t = localDateTime.format(formatter);
return t;
}
3.同步集合
Collections.synchronizedList()