本文整理了Java中java.time.OffsetDateTime.now()
方法的一些代码示例,展示了OffsetDateTime.now()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.now()
方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名: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 offset will be calculated from 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.
[中]从默认时区的系统时钟获取当前日期时间。
这将查询默认时区中的时钟#systemDefaultZone(),以获取当前日期时间。偏移量将根据时钟中的时区进行计算。
使用此方法将防止使用备用时钟进行测试,因为该时钟是硬编码的。
代码示例来源:origin: hibernate/hibernate-orm
@Override
public OffsetDateTime seed(SharedSessionContractImplementor session) {
return OffsetDateTime.now();
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public OffsetDateTime next(OffsetDateTime current, SharedSessionContractImplementor session) {
return OffsetDateTime.now();
}
代码示例来源:origin: apache/ignite
/**
* Reset statistics
*/
public void reset() {
statByType.forEach((t, s) ->
s.forEach((k, sh) -> sh.resetStatistics())
);
startTime = OffsetDateTime.now();
}
代码示例来源:origin: SonarSource/sonarqube
private void setCreatedAfterFromDates(IssueQuery.Builder builder, @Nullable Date createdAfter, @Nullable String createdInLast, boolean createdAfterInclusive) {
checkArgument(createdAfter == null || createdInLast == null, format("Parameters %s and %s cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_CREATED_IN_LAST));
Date actualCreatedAfter = createdAfter;
if (createdInLast != null) {
actualCreatedAfter = Date.from(
OffsetDateTime.now(clock)
.minus(Period.parse("P" + createdInLast.toUpperCase(Locale.ENGLISH)))
.toInstant());
}
builder.createdAfter(actualCreatedAfter, createdAfterInclusive);
}
代码示例来源:origin: prontera/spring-cloud-rest-tcc
@Override
public Set<EventPublisher> execute(EventPublisherMapper mapper) {
// 取出3秒前已经发送过至队列但是没有收到ack请求的消息,并进行重试
return mapper.selectLimitedEntityByEventStatusBeforeTheSpecifiedUpdateTime(EventStatus.PENDING, 300, OffsetDateTime.now().minusSeconds(3));
}
}
代码示例来源:origin: prontera/spring-cloud-rest-tcc
@Override
public int updateNonNullProperties(T entity) {
Preconditions.checkNotNull(entity, "entity in updating should not be NULL");
entity.setUpdateTime(OffsetDateTime.now());
return getMapper().updateByPrimaryKeySelective(entity);
}
代码示例来源:origin: prontera/spring-cloud-rest-tcc
@Override
public int update(T entity) {
Preconditions.checkNotNull(entity, "entity in updating should not be NULL");
entity.setUpdateTime(OffsetDateTime.now());
return getMapper().updateByPrimaryKey(entity);
}
代码示例来源:origin: jdbi/jdbi
@Override
public SqlStatementCustomizer createForMethod(Annotation annotation, Class<?> sqlObjectType, Method method) {
final String parameterName = ((Timestamped) annotation).value();
return stmt -> {
ZoneId zone = stmt.getConfig(TimestampedConfig.class).getTimezone();
stmt.bind(parameterName, OffsetDateTime.now(timeSource.apply(zone)));
};
}
代码示例来源:origin: prontera/spring-cloud-rest-tcc
/**
* 直接向服务查询, 不再自作聪明地在本地进行过期时间检查, 以免无法区分not found与conflict
*/
@Deprecated
private void checkExpireInLocal(TccRequest request, List<Participant> participantLinks) {
// 获取最接近过期的时间
final OffsetDateTime theClosestToExpire = fetchTheRecentlyExpireTime(participantLinks);
if (theClosestToExpire.minusSeconds(LEEWAY).isBefore(OffsetDateTime.now())) {
// 释放全部资源
cancel(request);
throw new ReservationAlmostToExpireException("there are resources be about to expire at " + theClosestToExpire);
}
}
代码示例来源:origin: neo4j/neo4j
private static String currentTimeZoneOffsetString()
{
ZoneOffset offset = OffsetDateTime.now().getOffset();
return offset.equals( UTC ) ? "+0000" : offset.toString().replace( ":", "" );
}
}
代码示例来源:origin: prontera/spring-cloud-rest-tcc
private void initializeOffsetDateTime(T entity) {
entity.setCreateTime(OffsetDateTime.now());
if (entity.getUpdateTime() == null) {
entity.setUpdateTime(IdentityDomain.DEFAULT_DATE_TIME);
}
if (entity.getDeleteTime() == null) {
entity.setDeleteTime(IdentityDomain.DEFAULT_DATE_TIME);
}
}
代码示例来源:origin: jdbi/jdbi
@Override
public SqlStatementCustomizer createForType(Annotation annotation, Class<?> sqlObjectType) {
return stmt -> stmt.bind("now", OffsetDateTime.now(stmt.getConfig(Config.class).clock));
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldFailWhenOffsetDateTimeIsSentWithRun() throws Exception
{
testFailureWithV2Value( ValueUtils.of( OffsetDateTime.now() ), "OffsetDateTime" );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldCallExternalErrorOnDateTimeWithOffset() throws Exception
{
assumeThat( packerUnderTest.version(), equalTo( 1L ) );
testUnpackableStructParametersWithKnownType( new Neo4jPackV2(), ValueUtils.of( OffsetDateTime.now() ),
"OffsetDateTime values cannot be unpacked with this version of bolt." );
}
代码示例来源:origin: jdbi/jdbi
@Test
public void offsetDateTime() {
OffsetDateTime dt = OffsetDateTime.now();
h.execute("insert into stuff(ts) values (?)", dt);
assertThat(h.createQuery("select ts from stuff").mapTo(OffsetDateTime.class).findOnly()).isEqualTo(dt);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void offsetDateTimeLosesOffset() {
OffsetDateTime dt = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.ofHours(-7));
h.execute("insert into stuff(ts) values (?)", dt);
assertThat(h.createQuery("select ts from stuff").mapTo(OffsetDateTime.class).findOnly().isEqual(dt)).isTrue();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void offsetDateTimeLosesOffset() {
OffsetDateTime dt = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.ofHours(-7));
h.execute("insert into stuff(ts) values (?)", dt);
assertThat(dt.isEqual(h.createQuery("select ts from stuff").mapTo(OffsetDateTime.class).findOnly())).isTrue();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void offsetDateTime() {
OffsetDateTime dt = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.UTC);
h.execute("insert into stuff(ts) values (?)", dt);
assertThat(h.createQuery("select ts from stuff").mapTo(OffsetDateTime.class).findOnly()).isEqualTo(dt);
}
代码示例来源:origin: kiegroup/jbpm
@Test
public void testParseDateAsDuration() {
OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1);
long parsedMilliseconds = DateTimeUtils.parseDateAsDuration(oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME));
assertTrue("Parsed date as duration is bigger than " + MINUTE_IN_MILLISECONDS, parsedMilliseconds <= MINUTE_IN_MILLISECONDS);
assertTrue("Parsed date as duration is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedMilliseconds, parsedMilliseconds > FIFTY_NINE_SECONDS_IN_MILLISECONDS);
}
代码示例来源:origin: kiegroup/jbpm
@Test
public void testParseRepeatablePeriodAndEndDateTime() {
OffsetDateTime twoMinutesFromNow = OffsetDateTime.now().plusMinutes(2);
String twoMinutesFromNowFormatted = twoMinutesFromNow.format(DateTimeFormatter.ISO_DATE_TIME);
String isoString = "R5/PT1M/" + twoMinutesFromNowFormatted;
long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString);
assertEquals(5L, parsedRepeatable[0]);
assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS);
assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS);
assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]);
}
内容来源于网络,如有侵权,请联系作者删除!