当前位置: 首页>>代码示例>>Java>>正文


Java OffsetTime类代码示例

本文整理汇总了Java中java.time.OffsetTime的典型用法代码示例。如果您正苦于以下问题:Java OffsetTime类的具体用法?Java OffsetTime怎么用?Java OffsetTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OffsetTime类属于java.time包,在下文中一共展示了OffsetTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerFormatters

import java.time.OffsetTime; //导入依赖的package包/类
@Override
public void registerFormatters(FormatterRegistry registry) {
	DateTimeConverters.registerConverters(registry);

	DateTimeFormatter dateFormatter = getFormatter(Type.DATE);
	DateTimeFormatter timeFormatter = getFormatter(Type.TIME);
	DateTimeFormatter dateTimeFormatter = getFormatter(Type.DATE_TIME);

	registry.addFormatterForFieldType(LocalDate.class,
			new TemporalAccessorPrinter(dateFormatter),
			new TemporalAccessorParser(LocalDate.class, dateFormatter));

	registry.addFormatterForFieldType(LocalTime.class,
			new TemporalAccessorPrinter(timeFormatter),
			new TemporalAccessorParser(LocalTime.class, timeFormatter));

	registry.addFormatterForFieldType(LocalDateTime.class,
			new TemporalAccessorPrinter(dateTimeFormatter),
			new TemporalAccessorParser(LocalDateTime.class, dateTimeFormatter));

	registry.addFormatterForFieldType(ZonedDateTime.class,
			new TemporalAccessorPrinter(dateTimeFormatter),
			new TemporalAccessorParser(ZonedDateTime.class, dateTimeFormatter));

	registry.addFormatterForFieldType(OffsetDateTime.class,
			new TemporalAccessorPrinter(dateTimeFormatter),
			new TemporalAccessorParser(OffsetDateTime.class, dateTimeFormatter));

	registry.addFormatterForFieldType(OffsetTime.class,
			new TemporalAccessorPrinter(timeFormatter),
			new TemporalAccessorParser(OffsetTime.class, timeFormatter));

	registry.addFormatterForFieldType(Instant.class, new InstantFormatter());

	registry.addFormatterForFieldAnnotation(new Jsr310DateTimeFormatAnnotationFormatterFactory());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:DateTimeFormatterRegistrar.java

示例2: test_isBeforeIsAfterIsEqual2

import java.time.OffsetTime; //导入依赖的package包/类
@Test
public void test_isBeforeIsAfterIsEqual2() {
    OffsetTime a = OffsetTime.of(11, 30, 59, 0, OFFSET_PTWO);
    OffsetTime b = OffsetTime.of(11, 30, 58, 0, OFFSET_PONE);  // a is before b due to offset
    assertEquals(a.isBefore(b), true);
    assertEquals(a.isEqual(b), false);
    assertEquals(a.isAfter(b), false);

    assertEquals(b.isBefore(a), false);
    assertEquals(b.isEqual(a), false);
    assertEquals(b.isAfter(a), true);

    assertEquals(a.isBefore(a), false);
    assertEquals(b.isBefore(b), false);

    assertEquals(a.isEqual(a), true);
    assertEquals(b.isEqual(b), true);

    assertEquals(a.isAfter(a), false);
    assertEquals(b.isAfter(b), false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:TCKOffsetTime.java

示例3: validateTestDataOffsetDTTypes

import java.time.OffsetTime; //导入依赖的package包/类
/**
 * Helper method for *SetObject* tests.
 * Validate the test data contained in the given ResultSet with following structure:
 * 1 - `id` INT
 * 2 - `ot1` VARCHAR
 * 3 - `ot2` BLOB
 * 4 - `odt1` VARCHAR
 * 5 - `odt2` BLOB
 * 
 * Additionally validate support for the types java.time.Offset[Date]Time in ResultSet.getObject().
 * 
 * @param tableName
 * @param expectedRowCount
 * @throws Exception
 */
private void validateTestDataOffsetDTTypes(String tableName, int expectedRowCount) throws Exception {
    Connection testConn = getConnectionWithProps("autoDeserialize=true"); // Offset[Date]Time are supported via object serialization too.
    Statement testStmt = testConn.createStatement();
    this.rs = testStmt.executeQuery("SELECT * FROM " + tableName);

    int rowCount = 0;
    while (rs.next()) {
        String row = "Row " + rs.getInt(1);
        assertEquals(++rowCount, rs.getInt(1));

        assertEquals(row, testOffsetTime, this.rs.getObject(2, OffsetTime.class));
        assertEquals(row, testOffsetTime, this.rs.getObject(3, OffsetTime.class));
        assertEquals(row, testOffsetDateTime, this.rs.getObject(4, OffsetDateTime.class));
        assertEquals(row, testOffsetDateTime, this.rs.getObject(5, OffsetDateTime.class));

        assertEquals(row, rowCount, this.rs.getInt("id"));

        assertEquals(row, testOffsetTime, this.rs.getObject("ot1", OffsetTime.class));
        assertEquals(row, testOffsetTime, this.rs.getObject("ot2", OffsetTime.class));
        assertEquals(row, testOffsetDateTime, this.rs.getObject("odt1", OffsetDateTime.class));
        assertEquals(row, testOffsetDateTime, this.rs.getObject("odt2", OffsetDateTime.class));
    }
    assertEquals(expectedRowCount, rowCount);
    testConn.close();
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:41,代码来源:StatementsTest.java

示例4: parse

import java.time.OffsetTime; //导入依赖的package包/类
@Override
public TemporalAccessor parse(String text, Locale locale) throws ParseException {
	DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale);
	if (LocalDate.class.equals(this.temporalAccessorType)) {
		return LocalDate.parse(text, formatterToUse);
	}
	else if (LocalTime.class.equals(this.temporalAccessorType)) {
		return LocalTime.parse(text, formatterToUse);
	}
	else if (LocalDateTime.class.equals(this.temporalAccessorType)) {
		return LocalDateTime.parse(text, formatterToUse);
	}
	else if (ZonedDateTime.class.equals(this.temporalAccessorType)) {
		return ZonedDateTime.parse(text, formatterToUse);
	}
	else if (OffsetDateTime.class.equals(this.temporalAccessorType)) {
		return OffsetDateTime.parse(text, formatterToUse);
	}
	else if (OffsetTime.class.equals(this.temporalAccessorType)) {
		return OffsetTime.parse(text, formatterToUse);
	}
	else {
		throw new IllegalStateException("Unsupported TemporalAccessor type: " + this.temporalAccessorType);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:TemporalAccessorParser.java

示例5: addValue

import java.time.OffsetTime; //导入依赖的package包/类
@Override
public Tuple addValue(Object value) {
  if(value instanceof Boolean
    || value instanceof Number
    || value instanceof Character
    || value instanceof String
    || value instanceof JsonObject
    || value instanceof JsonArray
    || value instanceof Buffer
    || value instanceof LocalTime
    || value instanceof OffsetTime
    || value instanceof LocalDate
    || value instanceof LocalDateTime
    || value instanceof OffsetDateTime) {
    add(value);
  } else {
    add(null);
  }
  return this;
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:21,代码来源:ArrayTuple.java

示例6: test_isBeforeIsAfterIsEqual1

import java.time.OffsetTime; //导入依赖的package包/类
@Test
public void test_isBeforeIsAfterIsEqual1() {
    OffsetTime a = OffsetTime.of(11, 30, 58, 0, OFFSET_PONE);
    OffsetTime b = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);  // a is before b due to time
    assertEquals(a.isBefore(b), true);
    assertEquals(a.isEqual(b), false);
    assertEquals(a.isAfter(b), false);

    assertEquals(b.isBefore(a), false);
    assertEquals(b.isEqual(a), false);
    assertEquals(b.isAfter(a), true);

    assertEquals(a.isBefore(a), false);
    assertEquals(b.isBefore(b), false);

    assertEquals(a.isEqual(a), true);
    assertEquals(b.isEqual(b), true);

    assertEquals(a.isAfter(a), false);
    assertEquals(b.isAfter(b), false);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:TCKOffsetTime.java

示例7: test_get

import java.time.OffsetTime; //导入依赖的package包/类
@Test(dataProvider="sampleTimes")
public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneOffset offset) {
    LocalDate localDate = LocalDate.of(y, o, d);
    LocalTime localTime = LocalTime.of(h, m, s, n);
    LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
    OffsetDateTime a = OffsetDateTime.of(localDateTime, offset);

    assertEquals(a.getYear(), localDate.getYear());
    assertEquals(a.getMonth(), localDate.getMonth());
    assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
    assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
    assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());

    assertEquals(a.getHour(), localDateTime.getHour());
    assertEquals(a.getMinute(), localDateTime.getMinute());
    assertEquals(a.getSecond(), localDateTime.getSecond());
    assertEquals(a.getNano(), localDateTime.getNano());

    assertEquals(a.toOffsetTime(), OffsetTime.of(localTime, offset));
    assertEquals(a.toString(), localDateTime.toString() + offset.toString());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:TCKOffsetDateTime.java

示例8: data_adjustInto

import java.time.OffsetTime; //导入依赖的package包/类
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 23, 5, 0, 0), null},
            {LocalDateTime.of(2012, Month.MARCH, 4, 0, 0), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 0, 0), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), null},
            {LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, null},
            {LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, null},

            {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZoneOffset.UTC), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, OFFSET_PONE), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), ZonedDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZONE_PARIS), ZonedDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZONE_PARIS), null},

            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetTime.of(22, 3, 0, 0, ZoneOffset.UTC), null, DateTimeException.class},
            {LocalDateTime.of(2012, 3, 4, 23, 5), null, null, NullPointerException.class},

    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:TCKLocalDateTime.java

示例9: test_isBeforeIsAfterIsEqual2nanos

import java.time.OffsetTime; //导入依赖的package包/类
@Test
public void test_isBeforeIsAfterIsEqual2nanos() {
    OffsetTime a = OffsetTime.of(11, 30, 59, 4, ZoneOffset.ofTotalSeconds(OFFSET_PONE.getTotalSeconds() + 1));
    OffsetTime b = OffsetTime.of(11, 30, 59, 3, OFFSET_PONE);  // a is before b due to offset
    assertEquals(a.isBefore(b), true);
    assertEquals(a.isEqual(b), false);
    assertEquals(a.isAfter(b), false);

    assertEquals(b.isBefore(a), false);
    assertEquals(b.isEqual(a), false);
    assertEquals(b.isAfter(a), true);

    assertEquals(a.isBefore(a), false);
    assertEquals(b.isBefore(b), false);

    assertEquals(a.isEqual(a), true);
    assertEquals(b.isEqual(b), true);

    assertEquals(a.isAfter(a), false);
    assertEquals(b.isAfter(b), false);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:TCKOffsetTime.java

示例10: constructor_nullOffset

import java.time.OffsetTime; //导入依赖的package包/类
@Test(expectedExceptions=NullPointerException.class)
public void constructor_nullOffset() throws Throwable  {
    Constructor<OffsetTime> con = OffsetTime.class.getDeclaredConstructor(LocalTime.class, ZoneOffset.class);
    con.setAccessible(true);
    try {
        con.newInstance(LocalTime.of(11, 30, 0, 0), null);
    } catch (InvocationTargetException ex) {
        throw ex.getCause();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:TCKOffsetTime.java

示例11: encode

import java.time.OffsetTime; //导入依赖的package包/类
@Override
public void encode(
        BsonWriter writer,
        OffsetTime value,
        EncoderContext encoderContext) {

    writer.writeString(value.toString());
}
 
开发者ID:cbartosiak,项目名称:bson-codecs-jsr310,代码行数:9,代码来源:OffsetTimeCodec.java

示例12: decode

import java.time.OffsetTime; //导入依赖的package包/类
@Override
public OffsetTime decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    return OffsetTime.parse(reader.readString());
}
 
开发者ID:cbartosiak,项目名称:bson-codecs-jsr310,代码行数:8,代码来源:OffsetTimeCodec.java

示例13: test_compareTo_bothNearStartOfDay

import java.time.OffsetTime; //导入依赖的package包/类
@Test
public void test_compareTo_bothNearStartOfDay() {
    OffsetTime a = OffsetTime.of(0, 10, 0, 0, OFFSET_PONE);
    OffsetTime b = OffsetTime.of(2, 30, 0, 0, OFFSET_PTWO);  // a is before b on instant scale
    assertEquals(a.compareTo(b) < 0, true);
    assertEquals(b.compareTo(a) > 0, true);
    assertEquals(a.compareTo(a) == 0, true);
    assertEquals(b.compareTo(b) == 0, true);
    assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TCKOffsetTime.java

示例14: test_withOffsetSameInstant

import java.time.OffsetTime; //导入依赖的package包/类
@Test
public void test_withOffsetSameInstant() {
    OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    OffsetTime test = base.withOffsetSameInstant(OFFSET_PTWO);
    OffsetTime expected = OffsetTime.of(12, 30, 59, 0, OFFSET_PTWO);
    assertEquals(test, expected);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TCKOffsetTime.java

示例15: test_with_adjustment

import java.time.OffsetTime; //导入依赖的package包/类
@Test
public void test_with_adjustment() {
    final OffsetTime sample = OffsetTime.of(23, 5, 0, 0, OFFSET_PONE);
    TemporalAdjuster adjuster = new TemporalAdjuster() {
        @Override
        public Temporal adjustInto(Temporal dateTime) {
            return sample;
        }
    };
    assertEquals(TEST_11_30_59_500_PONE.with(adjuster), sample);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:TCKOffsetTime.java


注:本文中的java.time.OffsetTime类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。