本文整理了Java中java.time.LocalDateTime.atOffset()
方法的一些代码示例,展示了LocalDateTime.atOffset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.atOffset()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:atOffset
[英]Combines this date-time with an offset to create an OffsetDateTime.
This returns an OffsetDateTime formed from this date-time at the specified offset. All possible combinations of date-time and offset are valid.
[中]将此日期时间与偏移量组合以创建OffsetDateTime。
这将返回从此日期时间在指定偏移量处形成的OffsetDateTime。日期时间和偏移量的所有可能组合均有效。
代码示例来源:origin: debezium/debezium
protected Object convertTimestampWithZone(Column column, Field fieldDefn, Object data) {
if (!(data instanceof DateTimeOffset)) {
return super.convertTimestampWithZone(column, fieldDefn, data);
}
final DateTimeOffset dto = (DateTimeOffset)data;
// Timestamp is provided in UTC time
final Timestamp utc = dto.getTimestamp();
final ZoneOffset offset = ZoneOffset.ofTotalSeconds(dto.getMinutesOffset() * 60);
return super.convertTimestampWithZone(column, fieldDefn, LocalDateTime.ofEpochSecond(utc.getTime() / 1000, utc.getNanos(), offset).atOffset(offset));
}
代码示例来源:origin: apache/storm
int dateInt = (int) timestamp.toLocalDateTime().atOffset(ZoneOffset.UTC).toLocalDate().toEpochDay();
int localTimeInt = (int) (localTimestamp % DateTimeUtils.MILLIS_PER_DAY);
int currentTimeInt = (int) (currentTimestamp % DateTimeUtils.MILLIS_PER_DAY);
代码示例来源:origin: stackoverflow.com
String input = "2015-08-21 03:15";
String offsetInfo = "GMT+05:30";
LocalDateTime ldt =
LocalDateTime.parse(input, DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm"));
ZoneOffset offset =
ZoneOffset.of(offsetInfo.substring(3)); // GMT-prefix needs to be filtered out
LocalDateTime result =
ldt.atOffset(offset).withOffsetSameInstant(ZoneOffset.UTC).toLocalDateTime();
System.out.print(result); // output: 2015-08-20T21:45
代码示例来源:origin: FINRAOS/DataGenerator
public DateTimeSequential(LocalDateTime start, Duration step, Direction direction) {
this.start = start;
this.step = step;
this.direction = direction;
this.offset = ZoneOffset.UTC;
this.current.set(start.atOffset(this.offset).toInstant().toEpochMilli());
}
代码示例来源:origin: Netflix/iceberg
private static long yearToTimestampMicros(int year) {
return ChronoUnit.MICROS.between(EPOCH,
LocalDateTime.of(year, 1, 1, 0, 0).atOffset(ZoneOffset.UTC));
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
@Override
public void writeTimestamp(TemporalAccessor value) throws IOException {
gen.writeStartObject();
gen.writeFieldName(ExtendedType.TIMESTAMP.serialized);
super.writeTimestamp(((LocalDateTime) value).atOffset(ZoneOffset.UTC)); // output date time in local time zone
gen.writeEndObject();
}
代码示例来源:origin: org.n52.wps/engine
@Override
public String generate(LocalDateTime value) {
return value.atOffset(ZoneOffset.UTC).toString();
}
代码示例来源:origin: FINRAOS/DataGenerator
public DateTimeSequential(LocalDateTime start, Duration step) {
this.start = start;
this.step = step;
this.direction = Direction.ASCENDING;
this.offset = ZoneOffset.UTC;
this.current.set(start.atOffset(this.offset).toInstant().toEpochMilli());
}
代码示例来源:origin: FINRAOS/DataGenerator
public DateTimeSequential() {
this.start = LocalDateTime.now();
this.step = Duration.ofDays(1);
this.direction = Direction.ASCENDING;
this.offset = ZoneOffset.UTC;
this.current.set(start.atOffset(this.offset).toInstant().toEpochMilli());
}
代码示例来源:origin: FINRAOS/DataGenerator
public DateTimeSequential(LocalDateTime start) {
this.start = start;
this.step = Duration.ofDays(1);
this.direction = Direction.ASCENDING;
this.offset = ZoneOffset.UTC;
this.current.set(start.atOffset(this.offset).toInstant().toEpochMilli());
}
代码示例来源:origin: Netflix/iceberg
@Override
public void write(int repetitionLevel, LocalDateTime value) {
column.writeLong(repetitionLevel,
ChronoUnit.MICROS.between(EPOCH, value.atOffset(ZoneOffset.UTC)));
}
}
代码示例来源:origin: Netflix/iceberg
@Override
public void write(LocalDateTime timestamp, Encoder encoder) throws IOException {
encoder.writeLong(ChronoUnit.MICROS.between(EPOCH, timestamp.atOffset(ZoneOffset.UTC)));
}
}
代码示例来源:origin: traneio/ndbc
@Override
public final void encodeBinary(final LocalDateTime value, final BufferWriter b) {
final Instant instant = value.atOffset(ZoneOffset.UTC).toInstant();
final long seconds = instant.getEpochSecond();
final long micros = instant.getLong(ChronoField.MICRO_OF_SECOND) + (seconds * 1000000);
b.writeLong(micros - POSTGRES_EPOCH_MICROS);
}
代码示例来源:origin: org.apache.qpid/qpid-broker-core
private Date convertToDate(TemporalAccessor t)
{
if(!t.isSupported(ChronoField.INSTANT_SECONDS))
{
t = LocalDateTime.of(LocalDate.from(t), LocalTime.MIN).atOffset(ZoneOffset.UTC);
}
return new Date((t.getLong(ChronoField.INSTANT_SECONDS) * 1000L)
+ t.getLong(ChronoField.MILLI_OF_SECOND));
}
};
代码示例来源:origin: org.jadira.usertype/usertype.extended
@Override
public Time toNonNullValue(LocalTime value) {
ZoneOffset currentDatabaseZone = databaseZone == null ? getDefault() : databaseZone;
OffsetDateTime zonedValue = LocalDateTime.of(
1970, 1, 1, value.getHour(), value.getMinute(), value.getSecond(), value.getNano()
).atOffset(currentDatabaseZone);
final Time time = new Time(zonedValue.toInstant().toEpochMilli());
return time;
}
代码示例来源:origin: de.adorsys.psd2/xs2a-impl
public Balance mapToBalance(Xs2aBalance balance) {
Balance target = new Balance();
BeanUtils.copyProperties(balance, target);
target.setBalanceAmount(amountModelMapper.mapToAmount(balance.getBalanceAmount()));
Optional.ofNullable(balance.getBalanceType())
.ifPresent(balanceType -> target.setBalanceType(BalanceType.fromValue(balanceType.getValue())));
Optional.ofNullable(balance.getLastChangeDateTime())
.ifPresent(lastChangeDateTime -> {
List<ZoneOffset> validOffsets = ZoneId.systemDefault().getRules().getValidOffsets(lastChangeDateTime);
target.setLastChangeDateTime(lastChangeDateTime.atOffset(validOffsets.get(0)));
});
return target;
}
代码示例来源:origin: Ninja-Squad/DbSetup
@Test
public void dateBinderBindsOffsetDateTime() throws SQLException {
Binder binder = Binders.dateBinder();
OffsetDateTime value = LocalDateTime.parse("1975-07-19T01:02:03.000").atOffset(ZoneOffset.UTC);
binder.bind(stmt, 1, value);
verify(stmt).setDate(eq(1),
eq(new Date(value.toInstant().toEpochMilli())),
calendarWithTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC)));
}
代码示例来源:origin: opendatakit/briefcase
void createInstance(String submissionTpl, LocalDate submissionDate, String value) {
String formattedSubmissionDate = submissionDate.atStartOfDay().atOffset(OffsetDateTime.now().getOffset()).format(ISO_OFFSET_DATE_TIME);
String instanceId = String.format("uuid00000000-0000-0000-0000-%012d", seq.getAndIncrement());
String instanceContent = String.format(submissionTpl, instanceId, formattedSubmissionDate, formattedSubmissionDate, value);
Path instanceDir = formDir.resolve("instances").resolve(instanceId);
createDirectories(instanceDir);
Path instanceFile = instanceDir.resolve("submission.xml");
UncheckedFiles.write(instanceFile, instanceContent);
}
代码示例来源:origin: Ninja-Squad/DbSetup
@Test
public void timestampBinderBindsOffsetDateTime() throws SQLException {
Binder binder = Binders.timestampBinder();
OffsetDateTime value = LocalDateTime.parse("1975-07-19T01:02:03.000").atOffset(ZoneOffset.UTC);
binder.bind(stmt, 1, value);
verify(stmt).setTimestamp(eq(1),
eq(Timestamp.from(value.toInstant())),
calendarWithTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC)));
}
代码示例来源:origin: Ninja-Squad/DbSetup
@Test
public void defaultBinderBindsOffsetDateTime() throws SQLException {
OffsetDateTime offsetDateTime = LocalDateTime.parse("1975-07-19T01:02:03.000").atOffset(ZoneOffset.UTC);
Binder binder = Binders.defaultBinder();
binder.bind(stmt, 1, offsetDateTime);
verify(stmt).setTimestamp(eq(1),
eq(Timestamp.from(offsetDateTime.toInstant())),
calendarWithTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC)));
}
内容来源于网络,如有侵权,请联系作者删除!