这里我喜欢的解决方案是因为它很简单,但是您需要一个Date和一个TimeZone作为参数来检索ZoneId
private ZoneId getZoneOffsetFor(final Date date, final TimeZone timeZone){ int offsetInMillis = getOffsetInMillis(date, timeZone); return ZoneOffset.ofTotalSeconds( offsetInMillis / 1000 );}private int getOffsetInMillis(final Date date, final TimeZone timeZone){ int offsetInMillis = timeZone.getRawOffset(); if(timeZone.inDaylightTime(date)){ offsetInMillis += timeZone.getDSTSavings(); } return offsetInMillis;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)