public class ParseDate {
public static final String DATE_FORMAT = "yyyy-MM-dd";
public static SimpleDateFormat DateFormatter = new SimpleDateFormat(DATE_FORMAT);
public static void main(String[] args) {
try {
System.out.println("Converting 2020-12-31 to "+DateFormatter.parse("2020-12-31"));
System.out.println("Converting 2020-06-30 to "+DateFormatter.parse("2020-06-30"));
} catch (ParseException e) {
e.printStackTrace();
}
}
}
Output:
Converting 2020-12-31 to Thu Dec 31 00:00:00 GMT 2020
Converting 2020-06-30 to Tue Jun 30 00:00:00 BST 2020
If I execute this code, I am getting different time zones (GMT and BST) as output.
How to get same time zone of Date object as output irrespective of different input strings.
When I was executed the code, I expect the date object should contain same time zone (either GMT or BST).
I have tried with the below time zone:

SimpleDateFormatandDate. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead useLocalDatefrom java.time, the modern Java date and time API. JustLocalDate.parse("2020-12-31")gives you theLocalDateobject that you want and need.Dateclass. It does not contain any time zone at all! You seem to be in (or have your JVM set to) a time zone that uses Greenwich Mean Time during standard time and British Summer Time during summer time (DST), which is part of the explanation of your different output.