import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.*;
public class DateUtils {
public static final String TIME_FORMAT_1 = "yyyyMMddHHmmss";
public static final String TIME_FORMAT_YMDHMS = "yyyy-MM-dd HH:mm:ss";
public static final String TIME_FORMAT_Y_M_D = "yyyy-MM-dd";
public static final String TIME_FORMAT_YMD = "yyyyMMdd";
/**
*将字符串日期
*举例:日期格式yyyyMMdd的字符串转为日期格式"yyyy-MM-dd"
* @param date 需要转换日期字符串 formatDateStr:需要转换日期字符串格式 converDateStr:需要转换为哪种格式的日期
* @return 返回格式化的日期
* @throws ParseException 分析时意外地出现了错误异常
*/
public static String strToDateFormat(String date,String formatDateStr,String converDateStr) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatDateStr);
Date dateTime = null;
try {
dateTime = simpleDateFormat.parse(date);
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(converDateStr);
return simpleDateFormat1.format(dateTime);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}