I was reading the API for the ZoneId
class. It states that there are three tipes of ID:
offset-style IDs with some form of prefix. Examples:
ZoneId.of("GMT+2");
ZoneId.of("UTC");
ZoneId.of("UT+01:00");
region-based. Examples:
ZoneId.of("Asia/Aden");
ZoneId.of("Etc/GMT+9");
ZoneId.of("Asia/Aqtau");
But what is the right syntax for the first kind? Documentation says that
[ID from ZoneOffset] consists of 'Z' and IDs starting with '+' or '-'.
What's the combination of String and ZoneOffset
object I'm supposed to use to create a ZoneId
of the first kind?
There are actually two question to be answered here
This is it:
ZoneId z;
z = ZoneId.of("Z"); //for UTC
z = ZoneId.of("+02:00");
z = ZoneId.of("-02:00");
here you can find the complete list
I wrongly thougt that
'Z' AND IDs starting with '+' or '-'
meant that you always needed a Z
prefix (to compose something like Z+02:00
). I think OR would be more appropriate.
ZoneOffset
object?No combination needed, you can either use a string or a ZoneOffset
object:
ZoneId z;
z = ZoneId.of("+02:00");
z = ZoneId.of(ZoneOffset.of("+02:00").getId());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With