I am trying to parse data in MySql format, I came across SimpleDateFormat . I can get the correct day and month, but I got a strange result for the year:
date = 2009-06-22; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date d = sdf.parse(date); System.println(date); System.println(d.getDate()); System.println(d.getMonth()); System.println(d.getYear());
Outputs:
2009-06-22 22 OK 5 Hum... Ok, months go from 0 to 11 109 o_O WTF ?
I tried changing the format to YYYY-MM-dd (got an error) and yy-MM-dd (didn't do anything). I am programming on Android, I do not know if this is important.
I currently work around this using split, but it is dirty and does not allow me to use the i18n features.
source share