本文介绍了Java 8 ZoneOffset-如何获取当前系统UTC偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取系统的当前 ZoneOffset .
我尝试这样做,但找不到方法.
另外,我也在寻找解决方案,但没有找到任何解决方法.
用Java可以做到吗?

I want to get current ZoneOffset of my system.
I tried to do that but I couldn't find a way.
Also, I was looking for a solution but I didn't find any.
Is it possible to do that in Java?


我的问题与不同.我想知道当前的系统UTC,而不是如何在TimeZone偏移量表示形式或TimeZone存储之间进行转换.


My question is different to this. I would like to know the current system UTC, not how to convert between TimeZone offset representation or TimeZone storing.

推荐答案

是的,有可能:

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

或者您可以将Instant实例替换为LocalDateTime实例:

or you can replace Instant instance with LocalDateTime instance:

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

这篇关于Java 8 ZoneOffset-如何获取当前系统UTC偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 00:19