Trying to convert ist into cst but I'm not getting the expected output if, I passes the hardcoded value. Expected output is>
IST:: 18-04-2022 14:11:53
CST:: 18-04-2022 03:41:53
and output I am getting after hardcode value (one month ahead)
IST:: 18-05-2022 14:10:33
CST:: 18-05-2022 03:40:33
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
public class datetime {
public static void main(String[] args) throws ParseException {
// TODO Auto-generated method stub
Calendar Local = Calendar.getInstance();
Local.set(2022, 4, 18, 14, 10);
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String ist = formatter.format(Local.getTime());
System.out.println("IST:: " + ist);
Date theist = formatter.parse(ist);
//Convertion of ist into cst
TimeZone cst = TimeZone.getTimeZone("CST");
formatter.setTimeZone(cst);
String cst1 = formatter.format(theist.getTime());
System.out.println("CST:: "+ cst1);
}
}