本文整理了Java中java.time.LocalTime.atOffset()
方法的一些代码示例,展示了LocalTime.atOffset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalTime.atOffset()
方法的具体详情如下:
包路径:java.time.LocalTime
类名称:LocalTime
方法名:atOffset
[英]Combines this time with an offset to create an OffsetTime.
This returns an OffsetTime formed from this time at the specified offset. All possible combinations of time and offset are valid.
[中]将此时间与偏移组合以创建偏移时间。
这将返回从此时开始在指定偏移量处形成的偏移时间。时间和偏移量的所有可能组合均有效。
代码示例来源:origin: hibernate/hibernate-orm
return ( (Time) value ).toLocalTime().atOffset( OffsetDateTime.now().getOffset() );
代码示例来源:origin: prestodb/presto
return timeWithUtcZoneFormat.parse(((String) value), LocalTime::from).atOffset(ZoneOffset.UTC);
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
@Override
public void writeTime(TemporalAccessor value) throws IOException {
gen.writeStartObject();
gen.writeFieldName(ExtendedType.TIME.serialized);
super.writeTime(((LocalTime) value).atOffset(ZoneOffset.UTC)); // output time in local time zone
gen.writeEndObject();
}
代码示例来源:origin: traneio/ndbc
@Override
public OffsetTime getOffsetTime() {
return get().atOffset(ZoneOffset.UTC);
}
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Override
public OffsetTime convert(Time in, Context context) throws Exception {
if (in == null) return null;
return in.toLocalTime().atOffset(offset);
}
}
代码示例来源:origin: org.simpleflatmapper/sfm-jdbc
@Override
public OffsetTime convert(Time in, Context context) throws Exception {
if (in == null) return null;
return in.toLocalTime().atOffset(offset);
}
}
代码示例来源:origin: org.n52.wps/engine
@Override
public String generate(LocalTime value) {
return value.atOffset(ZoneOffset.UTC).toString();
}
代码示例来源:origin: com.impossibl.pgjdbc-ng/pgjdbc-ng
@Override
protected Object decodeValue(Context context, Type type, Short typeLength, Integer typeModifier, ByteBuf buffer, Class<?> targetClass, Object targetContext) throws IOException {
Calendar calendar = targetContext != null ? (Calendar) targetContext : Calendar.getInstance();
long micros = buffer.readLong();
int tzOffsetSecs = -buffer.readInt();
if (micros == Long.MAX_VALUE || micros == Long.MIN_VALUE) {
return convertInfinityOutput(micros == Long.MAX_VALUE, type, targetClass);
}
ZoneOffset offset = ZoneOffset.ofTotalSeconds(tzOffsetSecs);
OffsetTime time = LocalTime.ofNanoOfDay(MICROSECONDS.toNanos(micros)).atOffset(offset);
return convertOutput(context, type, time, targetClass, calendar);
}
代码示例来源:origin: cero-t/sqltemplate
/**
* Get the column value as OffsetTime.
* @param rs ResultSet
* @param index column index
* @param zoneId zoneId
* @return column value
* @throws SQLException in case of extraction failure
*/
protected static OffsetTime getAsOffsetTime(ResultSet rs, int index, ZoneId zoneId) throws SQLException {
Time time = rs.getTime(index);
if (time != null) {
return time.toLocalTime().atOffset(zoneId.getRules().getOffset(Instant.now()));
}
return null;
}
}
代码示例来源:origin: com.impossibl.pgjdbc-ng/pgjdbc-ng
@Override
protected Object decodeValue(Context context, Type type, Short typeLength, Integer typeModifier, CharSequence buffer, Class<?> targetClass, Object targetContext) throws IOException, ParseException {
Calendar calendar = targetContext != null ? (Calendar) targetContext : Calendar.getInstance();
if (buffer.equals(POS_INFINITY) || buffer.equals(NEG_INFINITY)) {
return convertInfinityOutput(buffer.equals(POS_INFINITY), type, targetClass);
}
TemporalAccessor parsed = context.getTimeFormat().getParser().parse(buffer);
OffsetTime time;
if (parsed.isSupported(ChronoField.OFFSET_SECONDS)) {
time = OffsetTime.from(parsed);
}
else {
ZoneOffset offset =
ZoneOffset.ofTotalSeconds((int) MILLISECONDS.toSeconds(calendar.getTimeZone().getRawOffset()));
time = LocalTime.from(parsed).atOffset(offset);
}
return convertOutput(context, type, time, targetClass, calendar);
}
代码示例来源:origin: org.mybatis/mybatis-typehandlers-jsr310
private static OffsetTime getOffsetTime(Time time) {
if (time != null) {
return time.toLocalTime().atOffset(OffsetTime.now().getOffset());
}
return null;
}
}
代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core
public static OffsetTime makeOffsetTime(String literal) {
literal = DateTimeUtil.fixDateTimeFormat(literal);
if (!DateTimeUtil.isTime(literal)) {
return null;
}
if (DateTimeUtil.hasZone(literal) && DateTimeUtil.timeHasOffset(literal)) {
return null;
}
if (DateTimeUtil.hasZone(literal)) {
if (literal.contains("@")) {
int zoneIndex = literal.indexOf("@");
String zoneId = literal.substring(literal.indexOf('@') + 1);
ZoneId zone = ZoneId.of(zoneId);
LocalTime localTime = LocalTime.parse(literal.substring(0, zoneIndex), FEEL_TIME_FORMAT);
ZonedDateTime zdt = ZonedDateTime.of(LocalDate.now(zone), localTime, zone);
ZoneOffset offset = zone.getRules().getStandardOffset(zdt.toInstant());
return localTime.atOffset(offset);
} else {
return OffsetTime.parse(literal);
}
} else if (DateTimeUtil.hasOffset(literal)) {
return OffsetTime.parse(literal);
} else {
return OffsetTime.parse(literal + "Z");
}
}
代码示例来源:origin: goldmansachs/jdmn
public static OffsetTime makeOffsetTime(String literal) {
literal = DateTimeUtil.fixDateTimeFormat(literal);
if (!DateTimeUtil.isTime(literal)) {
return null;
}
if (DateTimeUtil.hasZone(literal) && DateTimeUtil.timeHasOffset(literal)) {
return null;
}
if (DateTimeUtil.hasZone(literal)) {
if (literal.contains("@")) {
int zoneIndex = literal.indexOf("@");
String zoneId = literal.substring(literal.indexOf('@') + 1);
ZoneId zone = ZoneId.of(zoneId);
LocalTime localTime = LocalTime.parse(literal.substring(0, zoneIndex), FEEL_TIME_FORMAT);
ZonedDateTime zdt = ZonedDateTime.of(LocalDate.now(zone), localTime, zone);
ZoneOffset offset = zone.getRules().getStandardOffset(zdt.toInstant());
return localTime.atOffset(offset);
} else {
return OffsetTime.parse(literal);
}
} else if (DateTimeUtil.hasOffset(literal)) {
return OffsetTime.parse(literal);
} else {
return OffsetTime.parse(literal + "Z");
}
}
代码示例来源:origin: traneio/ndbc
@Override
public final OffsetTime decodeBinary(final BufferReader b) {
final LocalTime time = LocalTime.ofNanoOfDay(b.readLong() * 1000);
final ZoneOffset zone = ZoneOffset.ofTotalSeconds(-b.readInt());
return time.atOffset(zone);
}
代码示例来源:origin: com.impossibl.pgjdbc-ng/pgjdbc-ng
private static Object convertOutput(Context context, Type type, LocalTime time, Class<?> targetClass, Calendar targetCalendar) throws ConversionException {
if (targetClass == LocalTime.class) {
return time;
}
if (targetClass == OffsetTime.class) {
ZoneOffset offset =
ZoneOffset.ofTotalSeconds((int) MILLISECONDS.toSeconds(targetCalendar.getTimeZone().getRawOffset()));
return time.atOffset(offset);
}
if (targetClass == String.class) {
return context.getTimeFormat().getPrinter().format(time);
}
if (targetClass == Time.class) {
LocalDate date = LocalDate.of(1970, 1, 1);
OffsetDateTime dateTime = date.atTime(time).atZone(targetCalendar.getTimeZone().toZoneId()).toOffsetDateTime().withOffsetSameInstant(ZoneOffset.UTC);
return new Time(dateTime.toInstant().toEpochMilli());
}
if (targetClass == Timestamp.class) {
LocalDate date = LocalDate.of(1970, 1, 1);
ZonedDateTime dateTime = date.atTime(time).atZone(targetCalendar.getTimeZone().toZoneId());
return Timestamp.from(dateTime.toInstant());
}
throw new ConversionException(type, targetClass);
}
代码示例来源:origin: Ninja-Squad/DbSetup
@Test
public void defaultBinderBindsOffsetTime() throws SQLException {
OffsetTime offsetTime = LocalTime.parse("01:02:03.000").atOffset(ZoneOffset.UTC);
Binder binder = Binders.defaultBinder();
binder.bind(stmt, 1, offsetTime);
verify(stmt).setTime(eq(1),
eq(Time.valueOf(offsetTime.toLocalTime())),
calendarWithTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC)));
}
代码示例来源:origin: Silverpeas/Silverpeas-Core
private OffsetDateTime normalize(final Temporal temporal) {
OffsetDateTime dateTime = asOffsetDateTime(temporal);
if (this.startDate != null) {
return TemporalConverter.applyByType(this.startDate,
t -> dateTime.with(LocalTime.MIDNIGHT.atOffset(ZoneOffset.UTC)),
t -> dateTime.with(t.toOffsetTime()));
}
return dateTime;
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Test
public void testConvertTime() throws Exception {
Time time = new Time(System.currentTimeMillis());
OffsetTime offsetTime = converter.convert(time, null);
assertEquals(time.toLocalTime().atOffset(offset), offsetTime);
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Override
public OffsetTime convert(Object o, Context context) throws Exception {
if (o == null) {
return null;
}
if (o instanceof Date) {
final Instant instant = Instant.ofEpochMilli(((Date) o).getTime());
return instant.atOffset(zone.getRules().getOffset(instant)).toOffsetTime();
}
if (o instanceof Instant) {
final Instant instant = (Instant) o;
return instant.atOffset(zone.getRules().getOffset(instant)).toOffsetTime();
}
if (o instanceof OffsetTime) {
return (OffsetTime) o;
}
if (o instanceof LocalDateTime) {
return ((LocalDateTime)o).atZone(zone).toOffsetDateTime().toOffsetTime();
}
if (o instanceof LocalTime) {
return ((LocalTime)o).atOffset(zone.getRules().getOffset(Instant.now()));
}
if (o instanceof TemporalAccessor) {
return OffsetTime.from((TemporalAccessor)o);
}
throw new IllegalArgumentException("Cannot convert " + o + " to OffsetTime");
}
代码示例来源:origin: org.simpleflatmapper/sfm-converter
@Override
public OffsetTime convert(Object o, Context context) throws Exception {
if (o == null) {
return null;
}
if (o instanceof Date) {
final Instant instant = Instant.ofEpochMilli(((Date) o).getTime());
return instant.atOffset(zone.getRules().getOffset(instant)).toOffsetTime();
}
if (o instanceof Instant) {
final Instant instant = (Instant) o;
return instant.atOffset(zone.getRules().getOffset(instant)).toOffsetTime();
}
if (o instanceof OffsetTime) {
return (OffsetTime) o;
}
if (o instanceof LocalDateTime) {
return ((LocalDateTime)o).atZone(zone).toOffsetDateTime().toOffsetTime();
}
if (o instanceof LocalTime) {
return ((LocalTime)o).atOffset(zone.getRules().getOffset(Instant.now()));
}
if (o instanceof TemporalAccessor) {
return OffsetTime.from((TemporalAccessor)o);
}
throw new IllegalArgumentException("Cannot convert " + o + " to OffsetTime");
}
内容来源于网络,如有侵权,请联系作者删除!