本文整理匯總了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());
}
示例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);
}
示例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();
}
示例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);
}
}
示例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;
}
示例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);
}
示例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());
}
示例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},
};
}
示例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);
}
示例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();
}
}
示例11: encode
import java.time.OffsetTime; //導入依賴的package包/類
@Override
public void encode(
BsonWriter writer,
OffsetTime value,
EncoderContext encoderContext) {
writer.writeString(value.toString());
}
示例12: decode
import java.time.OffsetTime; //導入依賴的package包/類
@Override
public OffsetTime decode(
BsonReader reader,
DecoderContext decoderContext) {
return OffsetTime.parse(reader.readString());
}
示例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);
}
示例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);
}
示例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);
}