Java sets DateFormat timezone to GMT + 1

What is the correct line to set the DateFormat time zone to GMT + 1? According to the documentation, it should be something like "GMT + 00:00". I have already tried other forms, but apparently I always return to GMT (my current time zone).

Thanks in advance!

+4
source share
2 answers

You can find the entire set of time zones using the following code snippet:

for (String id : TimeZone.getAvailableIDs()) { System.out.println(id); } 

And reuse it to set the time zone directly:

 DateFormat df = DateFormat.getDateInstance(); df.setTimeZone(TimeZone.getTimeZone(id)); 
+5
source

you can use

 TimeZone fixedUtcPlus1 = new SimpleTimeZone(TimeUnit.HOURS.toMillis(1), "GMT+1"); format.setTimeZone(fixedUtcPlus1); 

Or simply:

 TimeZone zone = TimeZone.getTimeZone("GMT+1"); format.setTimeZone(zone); 

(Apologies for the repeated changes around +1 and -1 ... bad diagnosis on my part. "GMT + 1" is fine, but its Etc equivalent - "Etc / GMT-1" is very confusing.)

+8
source

All Articles