How to get Century from date in Java

前端 未结 5 898
孤独总比滥情好
孤独总比滥情好 2021-01-04 20:41

How to get current Century from a date in Java?

For example the date \"06/03/2011\" according to format \"MM/dd/yyyy\". How can I get curre

5条回答
  •  清酒与你
    2021-01-04 21:23

    Date date = new SimpleDateFormat("MM/dd/yyyy").parse(yourString);
    
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    
    int century = (calendar.get(Calendar.YEAR) / 100) +1;
    

提交回复
热议问题