What is the best way to parse a date in MM/DD/YY format and adjust it to the current / previous century?

后端 未结 5 1753
野趣味
野趣味 2020-12-11 02:37

One of our customers wants to be able to enter a date with only 2 digits for the year component. The date will be in the past, so we want it to work for the previous century

5条回答
  •  眼角桃花
    2020-12-11 03:11

    Date deliverDate = new SimpleDateFormat("MM/dd/yy").parse(deliverDateString);
    String dateString2 = new SimpleDateFormat("yyyy-MM-dd").format(deliverDate);
    

    Working for me.

提交回复
热议问题