- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中java.time.zone.ZoneRules
类的一些代码示例,展示了ZoneRules
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneRules
类的具体详情如下:
包路径:java.time.zone.ZoneRules
类名称:ZoneRules
[英]The rules defining how the zone offset varies for a single time-zone.
The rules model all the historic and future transitions for a time-zone. ZoneOffsetTransition is used for known transitions, typically historic. ZoneOffsetTransitionRule is used for future transitions that are based on the result of an algorithm.
The rules are loaded via ZoneRulesProvider using a ZoneId. The same rules may be shared internally between multiple zone IDs.
Serializing an instance of ZoneRules will store the entire set of rules. It does not store the zone ID as it is not part of the state of this object.
A rule implementation may or may not store full information about historic and future transitions, and the information stored is only as accurate as that supplied to the implementation by the rules provider. Applications should treat the data provided as representing the best information available to the implementation of this rule.
The supplied implementations of this class are immutable and thread-safe.
[中]定义单个时区的分区偏移量如何变化的规则。
这些规则为时区的所有历史和未来过渡建模。ZoneOffsetTransition用于已知的过渡,通常是历史过渡。ZoneOffsetTransitionRule用于基于算法结果的未来转换。
使用ZoneId通过ZoneRulesProvider加载规则。多个区域ID之间可以在内部共享相同的规则。
序列化ZoneRules实例将存储整个规则集。它不存储区域ID,因为它不是此对象状态的一部分。
规则实现可能存储也可能不存储有关历史和未来转换的完整信息,存储的信息仅与规则提供程序提供给实现的信息一样准确。应用程序应将提供的数据视为代表执行此规则所需的最佳信息。
####实施者规范
提供的此类实现是不可变的,并且是线程安全的。
代码示例来源:origin: neo4j/neo4j
private static ZoneOffset parseOffset( Matcher matcher, Supplier<ZoneId> defaultZone )
{
ZoneOffset offset = parseOffset( matcher );
if ( offset == null )
{
ZoneId zoneId = defaultZone.get();
offset = zoneId instanceof ZoneOffset ? (ZoneOffset) zoneId : zoneId.getRules().getOffset( Instant.now() );
}
return offset;
}
代码示例来源:origin: prestodb/presto
@Test
public void testDateToTimestampCoercion()
{
// allow running tests with a connector that supports TIMESTAMP but not DATE
// ordinary date
MaterializedResult rows = h2QueryRunner.execute(TEST_SESSION, "SELECT DATE '2018-01-13'", ImmutableList.of(TIMESTAMP));
assertEquals(rows.getOnlyValue(), LocalDate.of(2018, 1, 13).atStartOfDay());
// date, which midnight was skipped in JVM zone
LocalDate forwardOffsetChangeAtMidnightInJvmZone = LocalDate.of(1970, 1, 1);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(forwardOffsetChangeAtMidnightInJvmZone.atStartOfDay()).size() == 0, "This test assumes certain JVM time zone");
rows = h2QueryRunner.execute(TEST_SESSION, DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(forwardOffsetChangeAtMidnightInJvmZone), ImmutableList.of(TIMESTAMP));
assertEquals(rows.getOnlyValue(), forwardOffsetChangeAtMidnightInJvmZone.atStartOfDay());
}
}
代码示例来源:origin: wildfly/wildfly
assertTrue(immutability.test(YearMonth.now()));
assertTrue(immutability.test(ZoneOffset.UTC));
assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC).nextTransition(Instant.now())));
assertTrue(immutability.test(ZoneOffsetTransitionRule.of(Month.JANUARY, 1, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, true, TimeDefinition.STANDARD, ZoneOffset.UTC, ZoneOffset.ofHours(1), ZoneOffset.ofHours(2))));
assertTrue(immutability.test(ZoneRules.of(ZoneOffset.UTC)));
assertTrue(immutability.test(ZonedDateTime.now()));
assertTrue(immutability.test(new JCIPImmutableObject()));
代码示例来源:origin: com.github.seratch/java-time-backport
/**
* Normalizes the time-zone ID, returning a {@code ZoneOffset} where possible.
* <p>
* The returns a normalized {@code ZoneId} that can be used in place of this ID.
* The result will have {@code ZoneRules} equivalent to those returned by this object,
* however the ID returned by {@code getId()} may be different.
* <p>
* The normalization checks if the rules of this {@code ZoneId} have a fixed offset.
* If they do, then the {@code ZoneOffset} equal to that offset is returned.
* Otherwise {@code this} is returned.
*
* @return the time-zone unique ID, not null
*/
public ZoneId normalized() {
try {
ZoneRules rules = getRules();
if (rules.isFixedOffset()) {
return rules.getOffset(Instant.EPOCH);
}
} catch (ZoneRulesException ex) {
// ignore invalid objects
}
return this;
}
代码示例来源:origin: jpos/jPOS
public void exec(CLIContext cli, String[] args) throws Exception
{
ZoneId zi = ZoneId.systemDefault();
Instant i = Instant.now();
cli.println(
" Zone ID: " + zi + " (" + zi.getDisplayName(TextStyle.FULL, Locale.getDefault()) + ") "
+ zi.getRules().getOffset(i)
);
cli.println (" UTC: " + i);
ZoneOffsetTransition tran = zi.getRules().nextTransition(i);
if (tran != null) {
Instant in = tran.getInstant();
cli.println (" Next transition: " + in + " (" + in.atZone(zi) + ")");
}
List<ZoneOffsetTransitionRule> l = zi.getRules().getTransitionRules();
for (ZoneOffsetTransitionRule r : l) {
cli.println (" Transition rule: " + r);
}
}
}
代码示例来源:origin: net.time4j/time4j-olson
ZonalOffset initialOffset = ZonalOffset.ofTotalSeconds(zoneRules.getOffset(Instant.MIN).getTotalSeconds());
List<ZonalTransition> transitions = new ArrayList<>();
List<DaylightSavingRule> rules = new ArrayList<>();
for (ZoneOffsetTransition zot : zoneRules.getTransitions()) {
Instant instant = zot.getInstant();
long posixTime = instant.getEpochSecond();
int previousOffset = zot.getOffsetBefore().getTotalSeconds();
int totalOffset = zot.getOffsetAfter().getTotalSeconds();
int dst = Math.toIntExact(zoneRules.getDaylightSavings(instant).getSeconds());
transitions.add(new ZonalTransition(posixTime, previousOffset, totalOffset, dst));
for (ZoneOffsetTransitionRule zotr : zoneRules.getTransitionRules()) {
DaylightSavingRule rule;
代码示例来源:origin: com.github.seratch/java-time-backport
List<ZoneOffset> validOffsets = rules.getValidOffsets(isoLDT);
ZoneOffset offset;
if (validOffsets.size() == 1) {
offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
ZoneOffsetTransition trans = rules.getTransition(isoLDT);
localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
offset = trans.getOffsetAfter();
代码示例来源:origin: stackoverflow.com
ZoneId zoneId = ZoneId.of("Australia/Sydney");
ZoneRules rules = zoneId.getRules();
ZoneOffsetTransition nextTransition = rules.nextTransition(Instant.now());
System.out.println("Next transition at: " +
nextTransition.getInstant().atZone(zoneId));
ZoneOffsetTransition nextNextTransition =
rules.nextTransition(nextTransition.getInstant());
System.out.println("Next transition after that at: " +
nextNextTransition.getInstant().atZone(zoneId));
代码示例来源:origin: org.onehippo.cms7/hippo-cms-api
private boolean isDST() {
return zoneId.getRules().isDaylightSavings(instant);
}
}
代码示例来源:origin: ical4j/ical4j
private static void addTransitionRules(ZoneId zoneId, int rawTimeZoneOffsetInSeconds, VTimeZone result) {
ZoneOffsetTransition zoneOffsetTransition = null;
if (!zoneId.getRules().getTransitions().isEmpty()) {
Collections.min(zoneId.getRules().getTransitions(),
Comparator.comparing(ZoneOffsetTransition::getDateTimeBefore));
for (ZoneOffsetTransitionRule transitionRule : zoneId.getRules().getTransitionRules()) {
int transitionRuleMonthValue = transitionRule.getMonth().getValue();
DayOfWeek transitionRuleDayOfWeek = transitionRule.getDayOfWeek();
代码示例来源:origin: infiniteautomation/ma-core-public
/**
* @param zdt
* @return
*/
public Instant getInstant(ZonedDateTime zdt) {
ZonedDateTime offset = zdt.withHour(hour).withMinute(minute).withSecond(second).withNano((int)(millisecond * 1000000l));
LocalDateTime ldt = zdt.toLocalDateTime();
ldt = ldt.withHour(hour).withMinute(minute).withSecond(second).withNano((int)(millisecond * 1000000l));
if(!zdt.getZone().getRules().isValidOffset(ldt, zdt.getOffset())) {
//Within a gap of DST so OR after the transition
ZoneOffsetTransition transition = zdt.getZone().getRules().nextTransition(zdt.toInstant());
if(!ldt.isAfter(transition.getDateTimeAfter())){
//In a gap so we shift our time forward to the end of the gap.
offset = transition.getDateTimeAfter().atZone(zdt.getZone());
}else {
//After a gap so ensure we use the next zone offset
offset = ldt.atOffset(transition.getOffsetAfter()).atZoneSimilarLocal(transition.getOffsetAfter());
}
}
return offset.toInstant();
}
}
代码示例来源:origin: com.helger/ph-oton-bootstrap3-pages
final ZoneOffset aZO = aZR.getOffset (aNow);
aRow.addCell (aDTZ.getDisplayName (TextStyle.SHORT, aDisplayLocale));
aRow.addCell (Duration.ofSeconds (aZO.getTotalSeconds ()).toString ());
aRow.addCell (EPhotonCoreText.getYesOrNo (aZR.isFixedOffset (), aDisplayLocale));
代码示例来源:origin: jpos/jPOS
p.printf("%s timezone: %s (%s) %s%n", indent, zi,
zi.getDisplayName(TextStyle.FULL, Locale.getDefault()),
zi.getRules().getOffset(instant).toString());
p.printf("%swatch service: %s%n", indent, getServer().getWatchServiceClassname());
List<ZoneOffsetTransitionRule> l = zi.getRules().getTransitionRules();
for (ZoneOffsetTransitionRule tr : l) {
p.printf("%s rule: %s%n", indent, tr.toString());
ZoneOffsetTransition tran = zi.getRules().nextTransition(instant);
if (tran != null) {
Instant in = tran.getInstant();
代码示例来源:origin: com.github.seratch/java-time-backport
List<ZoneOffset> validOffsets = rules.getValidOffsets(localDateTime);
ZoneOffset offset;
if (validOffsets.size() == 1) {
offset = validOffsets.get(0);
} else if (validOffsets.size() == 0) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds());
offset = trans.getOffsetAfter();
代码示例来源:origin: com.vaadin/vaadin-server
while (true) {
ZoneOffsetTransition t = rules
.nextTransition(i.toInstant());
if (t == null) {
break;
代码示例来源: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: org.mnode.ical4j/ical4j
private static void addTransitionRules(ZoneId zoneId, int rawTimeZoneOffsetInSeconds, VTimeZone result) {
ZoneOffsetTransition zoneOffsetTransition = null;
if (!zoneId.getRules().getTransitions().isEmpty()) {
Collections.min(zoneId.getRules().getTransitions(),
Comparator.comparing(ZoneOffsetTransition::getDateTimeBefore));
for (ZoneOffsetTransitionRule transitionRule : zoneId.getRules().getTransitionRules()) {
int transitionRuleMonthValue = transitionRule.getMonth().getValue();
DayOfWeek transitionRuleDayOfWeek = transitionRule.getDayOfWeek();
代码示例来源:origin: Graylog2/graylog2-server
final LocalDateTime localDateTime = (LocalDateTime) value;
final ZoneId defaultZoneId = ZoneId.systemDefault();
final ZoneOffset offset = defaultZoneId.getRules().getOffset(localDateTime);
date = Date.from(localDateTime.toInstant(offset));
} else if (value instanceof LocalDate) {
final LocalDateTime localDateTime = localDate.atStartOfDay();
final ZoneId defaultZoneId = ZoneId.systemDefault();
final ZoneOffset offset = defaultZoneId.getRules().getOffset(localDateTime);
date = Date.from(localDateTime.toInstant(offset));
} else if (value instanceof Instant) {
代码示例来源:origin: com.helger/ph-oton-bootstrap4-pages
final ZoneOffset aZO = aZR.getOffset (aNow);
aRow.addCell (aDTZ.getDisplayName (TextStyle.SHORT, aDisplayLocale));
aRow.addCell (Duration.ofSeconds (aZO.getTotalSeconds ()).toString ());
aRow.addCell (EPhotonCoreText.getYesOrNo (aZR.isFixedOffset (), aDisplayLocale));
代码示例来源:origin: prestodb/presto
@Test
public void testLocallyUnrepresentableTimeLiterals()
{
LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(2017, 4, 2, 2, 10);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotExist).isEmpty(), "This test assumes certain JVM time zone");
// This tests that both Presto runner and H2 can return TIMESTAMP value that never happened in JVM's zone (e.g. is not representable using java.sql.Timestamp)
@Language("SQL") String sql = DateTimeFormatter.ofPattern("'SELECT TIMESTAMP '''uuuu-MM-dd HH:mm:ss''").format(localTimeThatDidNotExist);
assertEquals(computeScalar(sql), localTimeThatDidNotExist); // this tests Presto and the QueryRunner
assertQuery(sql); // this tests H2QueryRunner
LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1970, 1, 1);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localDateThatDidNotHaveMidnight.atStartOfDay()).isEmpty(), "This test assumes certain JVM time zone");
// This tests that both Presto runner and H2 can return DATE value for a day which midnight never happened in JVM's zone (e.g. is not exactly representable using java.sql.Date)
sql = DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(localDateThatDidNotHaveMidnight);
assertEquals(computeScalar(sql), localDateThatDidNotHaveMidnight); // this tests Presto and the QueryRunner
assertQuery(sql); // this tests H2QueryRunner
LocalTime localTimeThatDidNotOccurOn19700101 = LocalTime.of(0, 10);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotOccurOn19700101.atDate(LocalDate.ofEpochDay(0))).isEmpty(), "This test assumes certain JVM time zone");
checkState(!Objects.equals(java.sql.Time.valueOf(localTimeThatDidNotOccurOn19700101).toLocalTime(), localTimeThatDidNotOccurOn19700101), "This test assumes certain JVM time zone");
sql = DateTimeFormatter.ofPattern("'SELECT TIME '''HH:mm:ss''").format(localTimeThatDidNotOccurOn19700101);
assertEquals(computeScalar(sql), localTimeThatDidNotOccurOn19700101); // this tests Presto and the QueryRunner
assertQuery(sql); // this tests H2QueryRunner
}
}
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!