Java SimpleDateFormat interpret parse-string as UTC

date, java

Solution

My assumption was wrong,

22.09.1985 00:00UTC is actually 22.09.1985 02:00CET

so

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date d = sdf.parse("22/09/1985");

is exactly what i wanted, the date i compared it with was wrong.

Problem

my timezone is GMT+1. so a "Date"-object with "22.09.1985 00:00UTC" prints "Sun Sep 22 01:00:00 CEST 1985" on the tostring function. Now i'm trying to create this date by parsing "22/09/1985" with simpleDateFormat ``` SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); sdf.setTimeZone(TimeZone.getDefault()); Date d = sdf.parse("22/09/1985"); => Sun Sep 22 00:00:00 CEST 1985 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); Date d = sdf.parse("22/09/1985"); => Sun Sep 22 02:00:00 CEST 1985 ``` how can i configure simpledateformat that it creates an Date which prints "Sun Sep 22 01:00:00 CEST 1985" with input string "22/09/1985"?

Original source