本文整理了Java中java.time.ZonedDateTime.now()
方法的一些代码示例,展示了ZonedDateTime.now()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.now()
方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:now
[英]Obtains the current date-time from the system clock in the default time-zone.
This will query the Clock#systemDefaultZone() in the default time-zone to obtain the current date-time. The zone and offset will be set based on the time-zone in the clock.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
[中]
代码示例来源:origin: hibernate/hibernate-orm
@Override
public ZonedDateTime seed(SharedSessionContractImplementor session) {
return ZonedDateTime.now();
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public ZonedDateTime next(ZonedDateTime current, SharedSessionContractImplementor session) {
return ZonedDateTime.now();
}
代码示例来源:origin: resilience4j/resilience4j
AbstractRetryEvent(String name, int numberOfAttempts, Throwable lastThrowable) {
this.name = name;
this.numberOfAttempts = numberOfAttempts;
this.creationTime = ZonedDateTime.now();
this.lastThrowable = lastThrowable;
}
代码示例来源:origin: resilience4j/resilience4j
AbstractCircuitBreakerEvent(String circuitBreakerName) {
this.circuitBreakerName = circuitBreakerName;
this.creationTime = ZonedDateTime.now();
}
代码示例来源:origin: neo4j/neo4j
public static DateTimeValue now( Clock clock )
{
return new DateTimeValue( ZonedDateTime.now( clock ) );
}
代码示例来源:origin: web3j/web3j
private static String getWalletFileName(WalletFile walletFile) {
DateTimeFormatter format = DateTimeFormatter.ofPattern(
"'UTC--'yyyy-MM-dd'T'HH-mm-ss.nVV'--'");
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
return now.format(format) + walletFile.getAddress() + ".json";
}
代码示例来源:origin: prestodb/presto
public String getBearerToken(String subject)
{
checkState(jwtSigner.isPresent(), "not configured");
JwtBuilder jwt = Jwts.builder()
.setSubject(subject)
.setExpiration(Date.from(ZonedDateTime.now().plusMinutes(5).toInstant()));
jwtSigner.get().accept(jwt);
jwtKeyId.ifPresent(keyId -> jwt.setHeaderParam(KEY_ID, keyId));
jwtIssuer.ifPresent(jwt::setIssuer);
jwtAudience.ifPresent(jwt::setAudience);
return jwt.compact();
}
代码示例来源:origin: apache/flink
private void createDashboardConfigFile() throws IOException {
try (FileWriter fw = createOrGetFile(webDir, "config")) {
fw.write(createConfigJson(DashboardConfiguration.from(webRefreshIntervalMillis, ZonedDateTime.now())));
fw.flush();
} catch (IOException ioe) {
LOG.error("Failed to write config file.");
throw ioe;
}
}
代码示例来源:origin: jenkinsci/jenkins
@RequirePOST
public HttpResponse doGenerateNewToken(@AncestorInPath User u, @QueryParameter String newTokenName) throws IOException {
if(!hasCurrentUserRightToGenerateNewToken(u)){
return HttpResponses.forbidden();
}
final String tokenName;
if (StringUtils.isBlank(newTokenName)) {
tokenName = String.format("Token created on %s", DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()));
}else{
tokenName = newTokenName;
}
ApiTokenProperty p = u.getProperty(ApiTokenProperty.class);
if (p == null) {
p = forceNewInstance(u, false);
u.addProperty(p);
}
ApiTokenStore.TokenUuidAndPlainValue tokenUuidAndPlainValue = p.tokenStore.generateNewToken(tokenName);
u.save();
return HttpResponses.okJSON(new HashMap<String, String>() {{
put("tokenUuid", tokenUuidAndPlainValue.tokenUuid);
put("tokenName", tokenName);
put("tokenValue", tokenUuidAndPlainValue.plainValue);
}});
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldFailWhenZonedDateTimeIsSentWithRun() throws Exception
{
testFailureWithV2Value( ValueUtils.of( ZonedDateTime.now() ), "ZonedDateTime" );
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void lastModified() {
ZonedDateTime now = ZonedDateTime.now();
String body = "foo";
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).lastModified(now).build();
Long expected = now.toInstant().toEpochMilli() / 1000;
StepVerifier.create(result)
.expectNextMatches(response -> expected.equals(response.headers().getLastModified() / 1000))
.expectComplete()
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void lastModified() {
ZonedDateTime now = ZonedDateTime.now();
Mono<ServerResponse> result = ServerResponse.ok().lastModified(now).build();
Long expected = now.toInstant().toEpochMilli() / 1000;
StepVerifier.create(result)
.expectNextMatches(response -> expected.equals(response.headers().getLastModified() / 1000))
.expectComplete()
.verify();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldCallExternalErrorOnDateTimeWithZoneName() throws Exception
{
assumeThat( packerUnderTest.version(), equalTo( 1L ) );
testUnpackableStructParametersWithKnownType( new Neo4jPackV2(), ValueUtils.of( ZonedDateTime.now() ),
"ZonedDateTime values cannot be unpacked with this version of bolt." );
}
代码示例来源:origin: prestodb/presto
@Test
public void testSerialization()
{
JsonCodec<AtopSplit> codec = JsonCodec.jsonCodec(AtopSplit.class);
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("+01:23"));
AtopSplit split = new AtopSplit(AtopTable.DISKS, HostAddress.fromParts("localhost", 123), now.toEpochSecond(), now.getZone());
AtopSplit decoded = codec.fromJson(codec.toJson(split));
assertEquals(decoded.getTable(), split.getTable());
assertEquals(decoded.getHost(), split.getHost());
assertEquals(decoded.getDate(), split.getDate());
assertEquals(decoded.getEpochSeconds(), split.getEpochSeconds());
assertEquals(decoded.getTimeZone(), split.getTimeZone());
}
}
代码示例来源:origin: neo4j/neo4j
@Test
@FrozenClockRule.TimeZone( "Europe/Stockholm" )
public void shouldAcquireCurrentDateTime()
{
assertEqualTemporal(
datetime( ZonedDateTime.now( clock ) ),
DateTimeValue.now( clock ) );
assertEqualTemporal( // Using the named UTC timezone
datetime( ZonedDateTime.now( clock.withZone( "UTC" ) ) ),
DateTimeValue.now( clock, "UTC" ) );
assertEqualTemporal( // Using the timezone defined as 0 hours offset from UTC
datetime( ZonedDateTime.now( clock.withZone( UTC ) ) ),
DateTimeValue.now( clock, "Z" ) );
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void notModifiedLastModified() {
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
RenderingResponse responseMono = RenderingResponse.create("bar")
.header(HttpHeaders.LAST_MODIFIED, DateTimeFormatter.RFC_1123_DATE_TIME.format(oneMinuteBeforeNow))
.build()
.block();
MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com")
.header(HttpHeaders.IF_MODIFIED_SINCE,
DateTimeFormatter.RFC_1123_DATE_TIME.format(now))
.build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
responseMono.writeTo(exchange, DefaultServerResponseBuilderTests.EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
StepVerifier.create(response.getBody())
.expectError(IllegalStateException.class)
.verify();
}
代码示例来源:origin: neo4j/neo4j
private static Stream<AnyValue> unsupportedValues()
{
return Stream.of(
nodeValue( 42, stringArray( "Person" ), EMPTY_MAP ),
newRelationshipValue(),
pointValue( CoordinateReferenceSystem.WGS84, new double[2] ),
byteArray( new byte[]{1, 2, 3} ),
Values.of( Duration.ofHours( 1 ) ),
Values.of( LocalDate.now() ),
Values.of( LocalTime.now() ),
Values.of( OffsetTime.now() ),
Values.of( LocalDateTime.now() ),
Values.of( ZonedDateTime.now() )
);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void notModifiedLastModified() {
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
EntityResponse<String> responseMono = EntityResponse.fromObject("bar")
.lastModified(oneMinuteBeforeNow)
.build()
.block();
MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com")
.header(HttpHeaders.IF_MODIFIED_SINCE,
DateTimeFormatter.RFC_1123_DATE_TIME.format(now))
.build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
responseMono.writeTo(exchange, DefaultServerResponseBuilderTests.EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
StepVerifier.create(response.getBody())
.expectError(IllegalStateException.class)
.verify();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void notModifiedLastModified() {
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
ServerResponse responseMono = ServerResponse.ok()
.lastModified(oneMinuteBeforeNow)
.syncBody("bar")
.block();
MockServerHttpRequest request = MockServerHttpRequest.get("http://example.com")
.header(HttpHeaders.IF_MODIFIED_SINCE,
DateTimeFormatter.RFC_1123_DATE_TIME.format(now))
.build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
responseMono.writeTo(exchange, EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
StepVerifier.create(response.getBody())
.expectError(IllegalStateException.class)
.verify();
}
代码示例来源:origin: prestodb/presto
@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layoutHandle, SplitSchedulingStrategy splitSchedulingStrategy)
{
AtopTableLayoutHandle handle = (AtopTableLayoutHandle) layoutHandle;
AtopTableHandle table = handle.getTableHandle();
List<ConnectorSplit> splits = new ArrayList<>();
ZonedDateTime end = ZonedDateTime.now(timeZone);
for (Node node : nodeManager.getWorkerNodes()) {
ZonedDateTime start = end.minusDays(maxHistoryDays - 1).withHour(0).withMinute(0).withSecond(0).withNano(0);
while (start.isBefore(end)) {
ZonedDateTime splitEnd = start.withHour(23).withMinute(59).withSecond(59).withNano(0);
Domain splitDomain = Domain.create(ValueSet.ofRanges(Range.range(TIMESTAMP_WITH_TIME_ZONE, 1000 * start.toEpochSecond(), true, 1000 * splitEnd.toEpochSecond(), true)), false);
if (handle.getStartTimeConstraint().overlaps(splitDomain) && handle.getEndTimeConstraint().overlaps(splitDomain)) {
splits.add(new AtopSplit(table.getTable(), node.getHostAndPort(), start.toEpochSecond(), start.getZone()));
}
start = start.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
}
}
return new FixedSplitSource(splits);
}
}
内容来源于网络,如有侵权,请联系作者删除!