Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java set DateFormat timezone to GMT+1

What is the correct string to set the DateFormat timezone to GMT+1? According the documentation it should be something like "GMT + 00:00". I already tried other forms but apparently I always fallback to GMT (my current timezone).

Thanks in advance!

like image 345
Rui Avatar asked Dec 12 '22 17:12

Rui


1 Answers

You can use

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

Or just:

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

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

like image 168
Jon Skeet Avatar answered Dec 25 '22 03:12

Jon Skeet