Java 8 ZoneOffset - How to get the current UTC system offset

I want to get the current ZoneOffset of my system.
I tried to do this, but I could not find a way.
Also, I was looking for a solution, but I did not find it.
Is it possible to do this in Java?

EDIT:
My question is different from this . I would like to know the current UTC system, and not how to convert between a TimeZone offset view or a TimeZone storage.

+4
source share
2 answers

Yes, it is possible:

ZoneOffset.systemDefault().getRules().getOffset(Instant.now())

or you can replace the Instant instance with a LocalDateTime instance:

ZoneOffset.systemDefault().getRules().getOffset(LocalDateTime.now())
+7

:

  • " " - - ZoneId.systemDefault()
  • "" - - Instant.now()

ZoneRules, :

ZoneOffset o = ZoneId.systemDefault().getRules().getOffset(Instant.now());

OffsetDateTime:

ZoneOffset o = OffsetDateTime.now().getOffset();

, OffsetDateTime.now() ZoneId.systemDefault(), Instant.now() .

+7

Source: https://habr.com/ru/post/1670868/


All Articles