I am facing issue in java while date formatting.
For all the other dates, this format is working fine. But for below date Thu Jan 06 03:30:51 IST 2022
when i use SimpleDateFormat I am getting below date as Output 2022-12-31T03:30:51
. Issue is Instead of year 2021 I am getting year as 2022
public static void main(String args[]) {
DateFormat targetFormat = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
Date date = new Date(122,0,6,3,30,51);//Thu Jan 06 03:30:51 IST 2022
date = DateUtils.addDays(date, -6);//Fri Dec 31 03:30:51 IST 2021
targetFormat.format(date);//2022-12-31T03:30:51
}
Please guide me