本文整理了Java中java.time.OffsetDateTime.of()
方法的一些代码示例,展示了OffsetDateTime.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.of()
方法的具体详情如下:
包路径:java.time.OffsetDateTime
类名称:OffsetDateTime
方法名:of
[英]Obtains an instance of OffsetDateTime from a year, month, day, hour, minute, second, nanosecond and offset.
This creates an offset date-time with the seven specified fields.
This method exists primarily for writing test cases. Non test-code will typically use other methods to create an offset time. LocalDateTime has five additional convenience variants of the equivalent factory method taking fewer arguments. They are not provided here to reduce the footprint of the API.
[中]从年、月、日、小时、分钟、秒、纳秒和偏移量中获取OffsetDateTime的实例。
这将创建带有七个指定字段的偏移日期时间。
这种方法主要用于编写测试用例。非测试代码通常会使用其他方法来创建偏移时间。LocalDateTime有五个附加的方便变量,它们是等效工厂方法的变体,使用的参数更少。这里不提供它们是为了减少API的占用空间。
代码示例来源:origin: debezium/debezium
@Override
protected Object convertTimestampWithZone(Column column, Field fieldDefn, Object data) {
if (data instanceof Long) {
LocalDateTime localDateTime = nanosToLocalDateTimeUTC((Long) data);
data = OffsetDateTime.of(localDateTime, ZoneOffset.UTC);
} else if (data instanceof java.util.Date) {
// any Date like subclasses will be given to us by the JDBC driver, which uses the local VM TZ, so we need to go
// back to GMT
data = OffsetDateTime.ofInstant(Instant.ofEpochMilli(((Date) data).getTime()), ZoneOffset.UTC);
}
return super.convertTimestampWithZone(column, fieldDefn, data);
}
代码示例来源:origin: debezium/debezium
/**
* Converts a value object for an expected JDBC type of {@link Types#TIMESTAMP_WITH_TIMEZONE}.
* The <a href="http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html">standard ANSI to Java 8 type
* mappings</a> specify that the preferred mapping (when using JDBC's {@link java.sql.ResultSet#getObject(int) getObject(...)}
* methods) in Java 8 is to return {@link OffsetDateTime} for these values.
* <p>
* This method handles several types of objects, including {@link OffsetDateTime}, {@link java.sql.Timestamp},
* {@link java.util.Date}, {@link java.time.LocalTime}, and {@link java.time.LocalDateTime}.
*
* @param column the column definition describing the {@code data} value; never null
* @param fieldDefn the field definition; never null
* @param data the data object to be converted into a {@link Date Kafka Connect date} type; never null
* @return the converted value, or null if the conversion could not be made and the column allows nulls
* @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls
*/
protected Object convertTimestampWithZone(Column column, Field fieldDefn, Object data) {
// epoch is the fallback value
return convertValue(column, fieldDefn, data, OffsetDateTime.of(LocalDate.ofEpochDay(0), LocalTime.MIDNIGHT, defaultOffset), (r) -> {
try {
r.deliver(ZonedTimestamp.toIsoString(data, defaultOffset, adjuster));
} catch (IllegalArgumentException e) {
}
});
}
代码示例来源:origin: embulk/embulk
@Test
public void testLegacy() {
testLegacyToFormat(OffsetDateTime.of(2017, 2, 28, 2, 0, 45, 0, ZoneOffset.UTC).toInstant(),
"%Y-%m-%dT%H:%M:%S %Z",
"Asia/Tokyo",
"2017-02-28T11:00:45 JST");
}
代码示例来源:origin: DV8FromTheWorld/JDA
this.timestamp = OffsetDateTime.of(ldt, offset);
代码示例来源:origin: embulk/embulk
@Test
public void testJava() {
testJavaToFormat(OffsetDateTime.of(2017, 2, 28, 2, 0, 45, 0, ZoneOffset.UTC).toInstant(),
"EEE MMM dd HH:mm:ss uuuu XXXXX",
"-07:00",
"Mon Feb 27 19:00:45 2017 -07:00");
}
代码示例来源:origin: embulk/embulk
@Test
public void testRuby() {
testRubyToFormat(OffsetDateTime.of(2017, 2, 28, 2, 0, 45, 0, ZoneOffset.UTC).toInstant(),
"%Y-%m-%dT%H:%M:%S %Z",
"-09:00",
"2017-02-27T17:00:45 -09:00");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void testSimpleDateTime() {
MapSettings settings = new MapSettings();
settings.appendProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01T12:13:14+0200");
settings.appendProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "version");
Clock clock = mock(Clock.class);
ProjectAnalysisInfo info = new ProjectAnalysisInfo(settings.asConfig(), clock);
info.start();
OffsetDateTime date = OffsetDateTime.of(2017, 1, 1, 12, 13, 14, 0, ZoneOffset.ofHours(2));
assertThat(info.analysisDate()).isEqualTo(Date.from(date.toInstant()));
assertThat(info.analysisVersion()).isEqualTo("version");
}
代码示例来源:origin: kiegroup/jbpm
@Test
public void testParseDateTime() {
OffsetDateTime hourAfterEpoch = OffsetDateTime.of(1970, 1, 1, 1, 0, 0, 0, ZoneOffset.UTC);
long parsedMilliseconds = DateTimeUtils.parseDateTime(hourAfterEpoch.format(DateTimeFormatter.ISO_DATE_TIME));
assertEquals(HOUR_IN_MILLISECONDS, parsedMilliseconds);
}
代码示例来源:origin: embulk/embulk
return OffsetDateTime.of(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, nanoOfSecond,
ZoneOffset.UTC);
代码示例来源:origin: apache/drill
/**
* Best effort parsing of the given value
*/
public static LocalDateTime parseBest(String value) {
TemporalAccessor parsed = getDateTimeFormatter().parse(value);
LocalDate datePart;
LocalTime timePart;
ZoneOffset zoneOffset;
long epochDay = 0, nanoSeconds = 0;
int offsetSeconds = 0;
// get different parsed parts
if (parsed.isSupported(ChronoField.EPOCH_DAY)) {
epochDay = parsed.getLong(ChronoField.EPOCH_DAY);
}
if (parsed.isSupported(ChronoField.NANO_OF_DAY)) {
nanoSeconds = parsed.getLong(ChronoField.NANO_OF_DAY);
}
if (parsed.isSupported(ChronoField.OFFSET_SECONDS)) {
offsetSeconds = parsed.get(ChronoField.OFFSET_SECONDS);
}
zoneOffset = ZoneOffset.ofTotalSeconds(offsetSeconds);
datePart = LocalDate.ofEpochDay(epochDay);
timePart = LocalTime.ofNanoOfDay(nanoSeconds);
return OffsetDateTime.of(datePart, timePart, zoneOffset).toLocalDateTime();
}
代码示例来源:origin: apache/tinkerpop
@Override
public <I extends InputShim> OffsetDateTime read(final KryoShim<I, ?> kryo, final I input, final Class<OffsetDateTime> clazz) {
return OffsetDateTime.of(kryo.readObject(input, LocalDateTime.class), kryo.readObject(input, ZoneOffset.class));
}
}
代码示例来源:origin: apache/tinkerpop
@Override
protected OffsetDateTime readValue(final ByteBuf buffer, final GraphBinaryReader context) throws SerializationException {
final LocalDateTime ldt = context.readValue(buffer, LocalDateTime.class, false);
final ZoneOffset zo = context.readValue(buffer, ZoneOffset.class, false);
return OffsetDateTime.of(ldt, zo);
}
代码示例来源:origin: embulk/embulk
return OffsetDateTime.from(given);
} else {
return OffsetDateTime.of(LocalDateTime.from(given), this.defaultZoneOffset);
return OffsetDateTime.of(dateFromDefault, timeFromDefault, givenZoneOffset);
} else {
return OffsetDateTime.of(dateFromDefault, timeFromDefault, this.defaultZoneOffset);
代码示例来源:origin: benas/random-beans
@Override
public OffsetDateTime getRandomValue() {
LocalDate randomLocalDate = localDateRandomizer.getRandomValue();
LocalTime randomLocalTime = localTimeRandomizer.getRandomValue();
ZoneOffset randomZoneOffset = zoneOffsetRandomizer.getRandomValue();
return OffsetDateTime.of(randomLocalDate, randomLocalTime, randomZoneOffset);
}
代码示例来源:origin: org.codehaus.groovy/groovy-datetime
/**
* Returns an {@link java.time.OffsetDateTime} of this offset and the provided {@link java.time.LocalDateTime}.
*
* @param self a ZoneOffset
* @param dateTime a LocalDateTime
* @return an OffsetDateTime
* @since 2.5.0
*/
public static OffsetDateTime leftShift(final ZoneOffset self, LocalDateTime dateTime) {
return OffsetDateTime.of(dateTime, self);
}
代码示例来源:origin: hprose/hprose-java
public Instant convertTo(DateTime dt) {
return OffsetDateTime.of(dt.year, dt.month, dt.day,
dt.hour, dt.minute, dt.second, dt.nanosecond,
dt.utc ? ZoneOffset.UTC :
ZoneOffset.of(TimeZoneUtil.DefaultTZ.getID())).toInstant();
}
代码示例来源:origin: org.codehaus.groovy/groovy-datetime
/**
* Returns an {@link java.time.OffsetDateTime} of this time and the provided {@link java.time.LocalDate}.
*
* @param self an OffsetTime
* @param date a LocalDate
* @return an OffsetDateTime
* @since 2.5.0
*/
public static OffsetDateTime leftShift(final OffsetTime self, LocalDate date) {
return OffsetDateTime.of(date, self.toLocalTime(), self.getOffset());
}
代码示例来源:origin: org.codehaus.groovy/groovy-datetime
/**
* Converts the Calendar to a corresponding {@link java.time.OffsetDateTime}.
*
* @param self a Calendar
* @return an OffsetDateTime
* @since 2.5.0
*/
public static OffsetDateTime toOffsetDateTime(final Calendar self) {
return OffsetDateTime.of(toLocalDateTime(self), getZoneOffset(self));
}
代码示例来源:origin: OpenGamma/Strata
public void test_addTo() {
assertEquals(P1D.addTo(LocalDate.of(2014, 6, 30)), LocalDate.of(2014, 7, 1));
assertEquals(P1W.addTo(
OffsetDateTime.of(2014, 6, 30, 0, 0, 0, 0, ZoneOffset.UTC)),
OffsetDateTime.of(2014, 7, 7, 0, 0, 0, 0, ZoneOffset.UTC));
}
代码示例来源:origin: com.esotericsoftware/kryo
public OffsetDateTime read (Kryo kryo, Input in, Class<OffsetDateTime> type) {
LocalDate date = LocalDateSerializer.read(in);
LocalTime time = LocalTimeSerializer.read(in);
ZoneOffset offset = ZoneOffsetSerializer.read(in);
return OffsetDateTime.of(date, time, offset);
}
}
内容来源于网络,如有侵权,请联系作者删除!