本文整理了Java中java.time.Clock.getZone()
方法的一些代码示例,展示了Clock.getZone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clock.getZone()
方法的具体详情如下:
包路径:java.time.Clock
类名称:Clock
方法名:getZone
[英]Gets the time-zone being used to create dates and times.
A clock will typically obtain the current instant and then convert that to a date or time using a time-zone. This method returns the time-zone used.
[中]获取用于创建日期和时间的时区。
时钟通常会获取当前时刻,然后使用时区将其转换为日期或时间。此方法返回使用的时区。
代码示例来源:origin: neo4j/neo4j
public ZoneId timezone()
{
return system.getZone();
}
代码示例来源:origin: apache/flume
public SyslogUtils(Integer defaultSize, Set<String> keepFields, boolean isUdp) {
this(defaultSize, keepFields, isUdp, Clock.system(Clock.systemDefaultZone().getZone()));
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final Clock clock = (Clock)source;
ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(Clock.class, "zone"), null);
context.convertAnother(clock.getZone());
writer.endNode();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void set_created_after_from_created_since() {
Date now = DateUtils.parseDateTime("2013-07-25T07:35:00+0100");
when(clock.instant()).thenReturn(now.toInstant());
when(clock.getZone()).thenReturn(ZoneOffset.UTC);
SearchRequest request = new SearchRequest()
.setCreatedInLast("1y2m3w4d");
assertThat(underTest.create(request).createdAfter().date()).isEqualTo(DateUtils.parseDateTime("2012-04-30T07:35:00+0100"));
assertThat(underTest.create(request).createdAfter().inclusive()).isTrue();
}
代码示例来源:origin: palatable/lambda
@Override
public ZoneId getZone() {
return clock.getZone();
}
代码示例来源:origin: sixt/ja-micro
@Before
public void setup() {
clock = mock(Clock.class);
when(clock.instant()).thenReturn(Instant.now());
when(clock.getZone()).thenReturn(ZoneId.systemDefault());
consumer = mock(KafkaConsumer.class);
committer = new OffsetCommitter(consumer, clock);
}
代码示例来源:origin: apache/metron
public static long parseTimestampToEpochMillis(String logTimestamp, Clock deviceClock) throws ParseException {
ZoneId deviceTimeZone = deviceClock.getZone();
代码示例来源:origin: apache/metron
@Test
public void testConfigureTimeZoneOffset() {
Map<String, Object> parserConfig = new HashMap<>();
parserConfig.put("deviceTimeZone", "UTC-05:00");
BasicAsaParser testParser = new BasicAsaParser();
testParser.configure(parserConfig);
testParser.init();
ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone());
ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5));
assertTrue(deviceTime.isEqual(referenceTime));
}
代码示例来源:origin: apache/metron
@Test
public void testConfigureTimeZoneText() {
Map<String, Object> parserConfig = new HashMap<>();
parserConfig.put("deviceTimeZone", "America/New_York");
Syslog5424Parser testParser = new Syslog5424Parser();
testParser.configure(parserConfig);
testParser.init();
ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone());
ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5));
assertTrue(deviceTime.isEqual(referenceTime));
}
代码示例来源:origin: apache/metron
@Test
public void testConfigureTimeZoneText() {
Map<String, Object> parserConfig = new HashMap<>();
parserConfig.put("deviceTimeZone", "America/New_York");
BasicAsaParser testParser = new BasicAsaParser();
testParser.configure(parserConfig);
testParser.init();
ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone());
ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5));
assertTrue(deviceTime.isEqual(referenceTime));
}
代码示例来源:origin: apache/metron
@Test
public void testConfigureTimeZoneOffset() {
Map<String, Object> parserConfig = new HashMap<>();
parserConfig.put("deviceTimeZone", "UTC-05:00");
Syslog3164Parser testParser = new Syslog3164Parser();
testParser.configure(parserConfig);
testParser.init();
ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone());
ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5));
assertTrue(deviceTime.isEqual(referenceTime));
}
代码示例来源:origin: apache/metron
@Test
public void testConfigureTimeZoneText() {
Map<String, Object> parserConfig = new HashMap<>();
parserConfig.put("deviceTimeZone", "America/New_York");
Syslog3164Parser testParser = new Syslog3164Parser();
testParser.configure(parserConfig);
testParser.init();
ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone());
ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5));
assertTrue(deviceTime.isEqual(referenceTime));
}
代码示例来源:origin: apache/metron
@Test
public void testConfigureTimeZoneOffset() {
Map<String, Object> parserConfig = new HashMap<>();
parserConfig.put("deviceTimeZone", "UTC-05:00");
Syslog5424Parser testParser = new Syslog5424Parser();
testParser.configure(parserConfig);
testParser.init();
ZonedDateTime deviceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), testParser.deviceClock.getZone());
ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochSecond(1475323200), ZoneOffset.ofHours(-5));
assertTrue(deviceTime.isEqual(referenceTime));
}
代码示例来源:origin: EvoSuite/evosuite
@Override
public ZoneId getZone() {
return baseClock.getZone();
}
@Override
代码示例来源:origin: apache/metron
@Test
public void testConfigureDefault() {
Map<String, Object> parserConfig = new HashMap<>();
BasicAsaParser testParser = new BasicAsaParser();
testParser.configure(parserConfig);
testParser.init();
assertTrue(testParser.deviceClock.getZone().equals(ZoneOffset.UTC));
}
代码示例来源:origin: apache/metron
@Test
public void testConfigureDefault() {
Map<String, Object> parserConfig = new HashMap<>();
Syslog5424Parser testParser = new Syslog5424Parser();
testParser.configure(parserConfig);
testParser.init();
assertTrue(testParser.deviceClock.getZone().equals(ZoneOffset.UTC));
}
代码示例来源:origin: apache/metron
@Test
public void testConfigureDefault() {
Map<String, Object> parserConfig = new HashMap<>();
Syslog3164Parser testParser = new Syslog3164Parser();
testParser.configure(parserConfig);
testParser.init();
assertTrue(testParser.deviceClock.getZone().equals(ZoneOffset.UTC));
}
代码示例来源:origin: apache/cxf
/**
* Add a date header at the current time using the ZoneOffset. Date format is http
*/
public static void addDateHeader(Map<String, List<String>> messageHeaders, ZoneOffset zoneOffset) {
String date = DateTimeFormatter.RFC_1123_DATE_TIME
.format(LocalDateTime.now().atZone(Clock.system(zoneOffset).getZone()));
messageHeaders.put("Date", Collections.singletonList(date));
}
代码示例来源:origin: EvoSuite/evosuite
@Override
public Clock withZone(ZoneId zone) {
if (zone.equals(baseClock.getZone())) { // intentional NPE
return this;
}
return new MockClock.MockTickClock(baseClock.withZone(zone), tickNanos);
}
@Override
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.xstream-java8
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final Clock clock = (Clock)source;
ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(Clock.class, "zone"), null);
context.convertAnother(clock.getZone());
writer.endNode();
}
内容来源于网络,如有侵权,请联系作者删除!