0
点赞
收藏
分享

微信扫一扫

Java日期的格式转化,从一种格式转化为另一种格式

东言肆语 2022-03-14 阅读 62
    public static void main(String[] args) {
        String old_str = "12-12月-2022";
        SimpleDateFormat new_format = new SimpleDateFormat("yyyy/MM/dd");
        SimpleDateFormat old_format = new SimpleDateFormat("dd-MM月-yyyy");
        Date date = null;
        try {
            date = old_format.parse(old_str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String new_str = new_format.format(date);

        System.out.println(new_str);
        
    }
举报

相关推荐

0 条评论