java获取年份的后两位


public static String getDate(Date strDate) {
        String date = null;
        if (strDate != null) {
            Calendar startTime = Calendar.getInstance();
            int year = startTime.get(Calendar.YEAR) - 20;
            // 这里初始化时间,然后设置年份。只以年份为基准,不看时间
            startTime.clear();
            startTime.set(Calendar.YEAR, year);
            SimpleDateFormat formatter = new SimpleDateFormat("yyMM");
            formatter.setLenient(false);
            formatter.set2DigitYearStart(startTime.getTime());
            try {
                date = formatter.format(strDate);
            } catch (Exception e) {
            }
        }
        return date;
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM