java.time.zone.ZoneRules.isDaylightSavings()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(2.1k)|赞(0)|评价(0)|浏览(378)

本文整理了Java中java.time.zone.ZoneRules.isDaylightSavings()方法的一些代码示例,展示了ZoneRules.isDaylightSavings()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneRules.isDaylightSavings()方法的具体详情如下:
包路径:java.time.zone.ZoneRules
类名称:ZoneRules
方法名:isDaylightSavings

ZoneRules.isDaylightSavings介绍

[英]Checks if the specified instant is in daylight savings.

This checks if the standard and actual offsets are the same at the specified instant.
[中]检查指定的时间是否为夏令时。
这将检查在指定的瞬间标准偏移和实际偏移是否相同。

代码示例

代码示例来源:origin: org.onehippo.cms7/hippo-cms-api

private boolean isDST() {
    return zoneId.getRules().isDaylightSavings(instant);
  }
}

代码示例来源:origin: kousen/java_8_recipes

public static void main(String[] args) {
    LocalDateTime now = LocalDateTime.now();
    List<ZonedDateTime> antarticZones =
        ZoneId.getAvailableZoneIds().stream()  // Stream<String>
            .filter(regionId -> regionId.contains("Antarctica"))
            .map(ZoneId::of)  // Stream<ZoneId>
            .map(now::atZone) // Stream<ZonedDateTime>
            .sorted(comparingInt(zoneId -> zoneId.getOffset().getTotalSeconds()))
            .collect(Collectors.toList());

    antarticZones.forEach(zdt ->
        System.out.printf("%7s: %25s %7s%n", zdt.getOffset(), zdt.getZone(),
            zdt.getZone().getRules().isDaylightSavings(zdt.toInstant())));
  }
}

代码示例来源:origin: com.github.seratch/java-time-backport

@Override
public boolean print(DateTimePrintContext context, StringBuilder buf) {
  ZoneId zone = context.getValue(TemporalQueries.zoneId());
  if (zone == null) {
    return false;
  }
  if (zone.normalized() instanceof ZoneOffset) {
    buf.append(zone.getId());
    return true;
  }
  Long epochSec = context.getTemporal().getLong(INSTANT_SECONDS);
  Instant instant;
  if (epochSec != null) {
    instant = Instant.ofEpochSecond(epochSec);
  } else {
    instant = Instant.ofEpochSecond(-200L * 365 * 86400);  // about 1770
  }
  TimeZone tz = TimeZone.getTimeZone(zone.getId());
  boolean daylight = zone.getRules().isDaylightSavings(instant);
  int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT);
  String text = tz.getDisplayName(daylight, tzstyle, context.getLocale());
  buf.append(text);
  return true;
}

代码示例来源:origin: com.squarespace.cldr/cldr-runtime

boolean daylight = zoneRules.isDaylightSavings(d.toInstant());

相关文章