I am trying to parse a String
in "dd-MM-yy" format to a Date
object. The problem is that it tries to guess the century for the date.
When specified from 01 to 31, year is interpreted as 2000s (21st Century) and 32 t0 99 is considered 1900s (20th Century).
SimpleDateFormat fm =new SimpleDateFormat("dd-MM-yy");
String datestr="21-11-31";
try {
Date date= fm.parse(datestr);
System.out.println(date);
} catch (ParseException e) {
}
Can anyone help me? How can I specify that I am only working in the 21st Century neatly. I am not exactly trying to look for tricks like manipulating the string or shifting the date based on the condition.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…