本文整理了Java中java.time.ZonedDateTime.toOffsetDateTime()
方法的一些代码示例,展示了ZonedDateTime.toOffsetDateTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.toOffsetDateTime()
方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:toOffsetDateTime
[英]Converts this date-time to an OffsetDateTime.
This creates an offset date-time using the local date-time and offset. The zone ID is ignored.
[中]将此日期时间转换为OffsetDateTime。
这将使用本地日期时间和偏移量创建偏移日期时间。区域ID被忽略。
代码示例来源:origin: spring-projects/spring-framework
@Override
public OffsetDateTime convert(Calendar source) {
return calendarToZonedDateTime(source).toOffsetDateTime();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public OffsetDateTime convert(ZonedDateTime source) {
return source.toOffsetDateTime();
}
}
代码示例来源:origin: org.springframework/spring-context
@Override
public OffsetDateTime convert(Calendar source) {
return calendarToZonedDateTime(source).toOffsetDateTime();
}
}
代码示例来源:origin: org.springframework/spring-context
@Override
public OffsetDateTime convert(ZonedDateTime source) {
return source.toOffsetDateTime();
}
}
代码示例来源:origin: google/data-transfer-project
@Override
public CalendarEventModel.CalendarEventTime apply(
Map<String, String> time, TransformerContext context) {
if (time == null) {
return null;
}
String dateTimeValue = time.get("dateTime");
String timeZone = time.get("timeZone");
if (dateTimeValue == null || timeZone == null) {
return null;
}
try {
OffsetDateTime dateTime =
ZonedDateTime.of(LocalDateTime.parse(dateTimeValue), ZoneId.of(timeZone))
.toOffsetDateTime();
return new CalendarEventModel.CalendarEventTime(dateTime, false);
} catch (DateTimeException e) {
context.problem(e.getMessage());
return null;
}
}
}
代码示例来源:origin: org.postgresql/postgresql
/**
* Formats {@link LocalDateTime} to be sent to the backend, thus it adds time zone.
* Do not use this method in {@link java.sql.ResultSet#getString(int)}
* @param localDateTime The local date to format as a String
* @return The formatted local date
*/
public synchronized String toString(LocalDateTime localDateTime) {
if (localDateTime.isAfter(MAX_LOCAL_DATETIME)) {
return "infinity";
} else if (LocalDateTime.MIN.equals(localDateTime)) {
return "-infinity";
}
// LocalDateTime is always passed with time zone so backend can decide between timestamp and timestamptz
ZonedDateTime zonedDateTime = localDateTime.atZone(getDefaultTz().toZoneId());
return toString(zonedDateTime.toOffsetDateTime());
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public OffsetDateTime toOffsetDateTime() {
return dt.toOffsetDateTime();
}
代码示例来源:origin: google/data-transfer-project
CalendarEventModel.CalendarEventTime start =
new CalendarEventModel.CalendarEventTime(
ZonedDateTime.now(ZoneId.of("GMT")).toOffsetDateTime(), false);
CalendarEventModel.CalendarEventTime end =
new CalendarEventModel.CalendarEventTime(
ZonedDateTime.now(ZoneId.of("GMT")).toOffsetDateTime(), false);
CalendarEventModel eventModel =
new CalendarEventModel(
代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures
return ((java.sql.Timestamp)value).toInstant()
.atZone(config.getZoneId())
.toOffsetDateTime();
} else {
return ((java.sql.Timestamp)value).toLocalDateTime();
return ((java.sql.Timestamp)value).toInstant()
.atZone(config.getZoneId())
.toOffsetDateTime();
} else {
return OffsetDateTime.parse(value.toString());
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Override
public OffsetDateTime convert(Date in, Context context) throws Exception {
if (in == null) return null;
return in.toInstant().atZone(dateTimeZone).toOffsetDateTime();
}
}
代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures
@Test
public void testLoadJdbcParamsWithConfigLocalDateTime() throws Exception {
testCall(db, "CALL apoc.load.jdbc('jdbc:derby:derbyDB','SELECT * FROM PERSON WHERE NAME = ?',['John'])",
(row) -> assertEquals( Util.map("NAME", "John", "HIRE_DATE", hireDate.toLocalDate(), "EFFECTIVE_FROM_DATE",
effectiveFromDate.toLocalDateTime(), "TEST_TIME", time.toLocalTime(), "NULL_DATE", null), row.get("row")));
ZoneId asiaTokio = ZoneId.of("Asia/Tokyo");
testCall(db, "CALL apoc.load.jdbc('jdbc:derby:derbyDB','SELECT * FROM PERSON WHERE NAME = ?',['John'], {config})",
map("config", map("timezone", asiaTokio.toString())),
(row) -> {
assertEquals( Util.map("NAME", "John",
"HIRE_DATE", hireDate.toLocalDate(),
"EFFECTIVE_FROM_DATE", effectiveFromDate.toInstant().atZone(asiaTokio).toOffsetDateTime(),
"TEST_TIME", time.toLocalTime(),
"NULL_DATE", null), row.get("row"));
});
}
代码示例来源:origin: com.sqlapp/sqlapp-core
public OffsetDateTime deserialize(JsonParser jsonParser,
DeserializationContext paramDeserializationContext)
throws IOException, JsonProcessingException {
if (jsonParser.getText() == null
|| jsonParser.getText().length() == 0) {
return null;
}
ZonedDateTime dateTime=toDateTime(jsonParser.getText());
return dateTime.toOffsetDateTime();
}
}
代码示例来源:origin: com.salesforce.servicelibs/grpc-contrib
public static Timestamp fromZonedDateTimeUtc(@Nonnull ZonedDateTime zonedDateTime) {
checkNotNull(zonedDateTime, "zonedDateTime");
return fromOffsetDateTimeUtc(zonedDateTime.toOffsetDateTime());
}
}
代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core
public OffsetTime time(LocalDate from) {
if (from == null) {
return null;
}
return from.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime().toOffsetTime();
}
public OffsetTime time(OffsetTime from) {
代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core
public OffsetTime time(LocalDate from) {
if (from == null) {
return null;
}
return from.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime().toOffsetTime();
}
public OffsetTime time(OffsetTime from) {
代码示例来源:origin: com.palantir.remoting3/jersey-servers
@Override
public String toString(final ZonedDateTime value) {
checkArgument(value != null);
return value.toOffsetDateTime().toString();
}
}
代码示例来源:origin: yegor256/cactoos
/**
* Parses the date using the formatter to create
* {@link OffsetDateTime} instances.
* @param date The date to parse.
* @param formatter The formatter to use.
*/
public OffsetDateTimeOf(final CharSequence date,
final DateTimeFormatter formatter) {
this.parsed = new UncheckedScalar<>(
() -> ZonedDateTime.from(formatter.parse(date)).toOffsetDateTime()
);
}
代码示例来源:origin: net.tirasa.connid/connector-framework-internal
@Override
public void serialize(final Object object, final ObjectEncoder encoder) {
final ZonedDateTime val = (ZonedDateTime) object;
// Make sure we have timezone as (numeric) offset instead of
// using zone ID. We do this by invoking toOffsetDateTime().
// This makes the timestamp ISO-8601 compatible and therefore
// more portable.
encoder.writeStringContents(val.toOffsetDateTime().toString());
}
});
代码示例来源:origin: com.github.robozonky/robozonky-api
public static OffsetDateTime toOffsetDateTime(final String format, final String date) {
switch (format) { // the only two formats, as confirmed via e-mail with Zonky employees
case "yyyy-MM":
return YearMonth.parse(date, YEAR_MONTH)
.atDay(1)
.atStartOfDay(Defaults.ZONE_ID).toOffsetDateTime();
case "yyyy-MM-dd'T'HH:mm:ssZ":
return OffsetDateTime.parse(date, DateTimeFormatter.ISO_DATE_TIME);
default:
throw new IllegalArgumentException("Unknown date format ID: " + format);
}
}
代码示例来源:origin: org.jadira.usertype/usertype.core
@Override
public OffsetTime fromNonNullValue(Timestamp value) {
ZoneId currentJavaZone = javaZone == null ? getDefaultZoneId() : javaZone;
ZonedDateTime zonedDateTime = value.toInstant().with(ChronoField.NANO_OF_SECOND, value.getNanos()).atZone(currentJavaZone);
OffsetDateTime dateTime = zonedDateTime.toOffsetDateTime();
OffsetTime time = dateTime.toOffsetTime();
return time;
}
内容来源于网络,如有侵权,请联系作者删除!