I was reading theAPI 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());
Combine the "UTC" and ZoneOffset object to get your ZoneId
ZoneId z = ZoneId.ofOffset("UTC",ZoneOffset.UTC);
For better explanation visit this link http://www.java2s.com/Tutorials/Java/java.time/ZoneId/2180__ZoneId.ofOffset_String_prefix_ZoneOffset_offset_.htm
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.