Java has 3 completely separate APIs for 'date stuff'.
There's java.util.Date
(as well as TimeZone
, which is what you use here, and a bunch of things that hang off of this, such as java.sql.Timestamp
which inherits it).
There's java.util.Calendar
(and GregorianCalendar
and a few others).
There's everything in the java.time
package.
Why are there 3 APIs? Because the Date one is so incredibly boneheaded, it needed to be replaced. Unfortunately, the replacement was even worse, so that too needed to be replaced. Fortunately, the third time really was the charm, and java.time
is fantastic.
SOLUTION: Don't use the old obsolete bad APIs. If it starts with java.util
, you don't want it.
You want java.time.ZoneId
which represents an actual zone. This is something like Europe/Amsterdam
, not something useless, like CEST
or even the most useless, +01:00
. Those latter two are fragile as all get out and do not allow any actual math. For example, an offset-based zone doesn't let you 'add an hour' - depending on where on the planet an appointment was made, 'add an hour' can mean different things (Daylight Savings Time is a thing!). CEST
is too broad; the places on the planet that 'use CEST' changes all the time. Case in point: The EU passed a motion that all EU countries should move away from DST. But not all of the EU may choose the same zone to 'stick to', so that's an upcoming change of definition right there already.
If nevertheless you have one of these mostly useless zones, java.time.ZoneOffset
can represent this.
They will error if you provide gobbledygook.