Java 字符串日期转换成另外一种格式

 /**
     * @param date
     * @param oldPattern
     * @param newPattern
     * @Description 将字符串日期格式化成另外一种格式字符串
     * @Throws
     * @Return java.lang.String
     * @Date 2023-04-21 17:41:16
     * @Author WangKun
     */
    public static String getFormatDate(String date, String oldPattern, String newPattern) {
        try {
            SimpleDateFormat sdf1 = new SimpleDateFormat(oldPattern);
            SimpleDateFormat sdf2 = new SimpleDateFormat(newPattern);
            Date date1Date = sdf1.parse(date);
            return sdf2.format(date1Date);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

你可能感兴趣的:(java,开发语言,servlet)