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: