I got lost between the documentation and the numerous time-related questions found by google.
What I want is very simple: a string that represents the running timezone in the “[+/-] [number] [number] [number] [number]” format (for instance “+0100”).
My current code is:
Calendar cal = Calendar.getInstance(); TimeZone tz = cal.getTimeZone(); String gmt = "" + tz.getID();
which returns “GMT” in my location, which I assume is the short version (3 letters) of the timezones.
Here is the code I actually ended up using, I hope it helps someone.
Date today = Calendar.getInstance().getTime(); SimpleDateFormat sdf = new SimpleDateFormat("Z"); String gmt = sdf.format(today);