String req ="0229191315"
private static DateFormat dateFrmtGmt - new SimpleDateFormat ("EEE MMM d HH:mm:ss z yyyy", Locale.ENGLISH);
SimpleDateFormat sdf=new SimpleDateFormat( "MMddHHmmss");
cal.setTime(sdf.parse(gmtDate));
cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
dateFrmtGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
return cal;
String = "0229191315" returns Fri Mar 1 19:13:15 GMT 2024
While string="0301191315" returns Fri 1 mar 19:13:15 GMT 2024
For all the dates it is setting correct date and time but for 28 and 29 Jan 2024 settings value as 29 Feb and 1 March respectively .
The issue is that you are parsing the input without a year. Looking at the documentation of the SimpleDateFormat.parse() method.
Since year 1970 didn't had a February 29 date the parse returned March 1. After that you set the actual year but the date remains as it was parsed.
See a modern approach to resolve this issue using the java.time package in this answer: https://stackoverflow.com/a/44470949/721855