本文整理了Java中java.time.LocalDateTime.of()
方法的一些代码示例,展示了LocalDateTime.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.of()
方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:of
[英]Obtains an instance of LocalDateTime from year, month, day, hour and minute, setting the second and nanosecond to zero.
The day must be valid for the year and month, otherwise an exception will be thrown. The second and nanosecond fields will be set to zero.
[中]从年、月、日、小时和分钟获取LocalDateTime的实例,将秒和纳秒设置为零。
日期必须对年和月有效,否则将引发异常。第二个和纳秒字段将设置为零。
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderAscendingLocalDateTimeArray() throws Exception
{
Object o0 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 0 )};
Object o1 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 1 )};
Object o2 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 2 )};
Object o3 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 3 )};
Object o4 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 4 )};
Object o5 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 5 )};
shouldRangeSeekInOrder( IndexOrder.ASCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderAscendingLocalDateTimeArray() throws Exception
{
Object o0 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 0 )};
Object o1 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 1 )};
Object o2 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 2 )};
Object o3 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 3 )};
Object o4 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 4 )};
Object o5 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 5 )};
shouldSeekInOrderExactWithRange( IndexOrder.ASCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderDescendingLocalDateTimeArray() throws Exception
{
Object o0 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 0 )};
Object o1 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 1 )};
Object o2 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 2 )};
Object o3 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 3 )};
Object o4 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 4 )};
Object o5 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 5 )};
shouldSeekInOrderExactWithRange( IndexOrder.DESCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderDescendingLocalDateTimeArray() throws Exception
{
Object o0 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 0 )};
Object o1 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 1 )};
Object o2 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 2 )};
Object o3 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 3 )};
Object o4 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 4 )};
Object o5 = new LocalDateTime[]{LocalDateTime.of( 10, 10, 10, 10, 10, 10, 5 )};
shouldRangeSeekInOrder( IndexOrder.DESCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: kiegroup/optaplanner
@Test
public void createRandomIteratorForLocalDateTime() {
Random workingRandom = mock(Random.class);
LocalDateTime fromTime = LocalDateTime.of(2016, 7, 1, 4, 5, 12);
LocalDateTime toTime = LocalDateTime.of(2016, 7, 3, 12, 15, 12);
when(workingRandom.nextInt(anyInt())).thenReturn(3, 0);
assertElementsOfIterator(new TemporalValueRange<>(fromTime, toTime, 10, ChronoUnit.MINUTES).createRandomIterator(workingRandom),
LocalDateTime.of(2016, 7, 1, 4, 35, 12));
}
代码示例来源:origin: MorphiaOrg/morphia
@Test
public void testConversion() throws ParseException {
Calendar cal = Calendar.getInstance();
cal.set(2016, Calendar.MAY, 1, 12, 30, 45);
cal.set(Calendar.MILLISECOND, 718);
assertFormat(LocalDateTime.of(2016, 5, 1, 12, 30, 45, 718004350), cal.getTime());
compare(LocalDateTime.class, LocalDateTime.now());
compare(LocalDateTime.class, LocalDateTime.of(12016, 3, 11, 3, 30));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBindLocalDateTime() {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("localDateTime", LocalDateTime.of(2009, 10, 31, 12, 0));
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
String value = binder.getBindingResult().getFieldValue("localDateTime").toString();
assertTrue(value.startsWith("10/31/09"));
assertTrue(value.endsWith("12:00 PM"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBindLocalDateTimeAnnotated() {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("localDateTimeAnnotated", LocalDateTime.of(2009, 10, 31, 12, 0));
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
String value = binder.getBindingResult().getFieldValue("localDateTimeAnnotated").toString();
assertTrue(value.startsWith("Oct 31, 2009"));
assertTrue(value.endsWith("12:00:00 PM"));
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testJPACallback() {
Long personId = 1L;
doInJPA( this::entityManagerFactory, entityManager -> {
Person person = new Person();
person.id = personId;
person.name = "John Doe";
person.dateOfBirth = Timestamp.valueOf(LocalDateTime.of( 2000, 1, 1, 0, 0, 0 ));
entityManager.persist( person );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
Person person = entityManager.find( Person.class, personId );
assertTrue(person.age > 0);
} );
}
代码示例来源:origin: debezium/debezium
@Test
public void shouldReturnLocalDateTimeInstanceWhenConvertingLocalDateToLocalDateTime() {
LocalDate now = LocalDate.now();
assertThat(Conversions.toLocalDateTime(now)).isEqualTo(LocalDateTime.of(now, LocalTime.MIDNIGHT));
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldPackLocalDateTimeWithTimeZoneId()
{
LocalDateTime localDateTime = LocalDateTime.of( 1999, 12, 30, 9, 49, 20, 999999999 );
ZoneId zoneId = ZoneId.of( "Europe/Stockholm" );
ZonedDateTime zonedDateTime = ZonedDateTime.of( localDateTime, zoneId );
PackedOutputArray packedOutput = pack( datetime( zonedDateTime ) );
ByteBuffer buffer = ByteBuffer.wrap( packedOutput.bytes() );
buffer.getShort(); // skip struct header
assertEquals( INT_32, buffer.get() );
assertEquals( localDateTime.toEpochSecond( UTC ), buffer.getInt() );
assertEquals( INT_32, buffer.get() );
assertEquals( localDateTime.getNano(), buffer.getInt() );
buffer.getShort(); // skip zoneId string header
byte[] zoneIdBytes = new byte[zoneId.getId().getBytes( UTF_8 ).length];
buffer.get( zoneIdBytes );
assertEquals( zoneId.getId(), new String( zoneIdBytes, UTF_8 ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldPackLocalDateTimeWithTimeZoneOffset()
{
LocalDateTime localDateTime = LocalDateTime.of( 2015, 3, 23, 19, 15, 59, 10 );
ZoneOffset offset = ZoneOffset.ofHoursMinutes( -5, -15 );
ZonedDateTime zonedDateTime = ZonedDateTime.of( localDateTime, offset );
PackedOutputArray packedOutput = pack( datetime( zonedDateTime ) );
ByteBuffer buffer = ByteBuffer.wrap( packedOutput.bytes() );
buffer.getShort(); // skip struct header
assertEquals( INT_32, buffer.get() );
assertEquals( localDateTime.toEpochSecond( UTC ), buffer.getInt() );
assertEquals( localDateTime.getNano(), buffer.get() );
assertEquals( INT_16, buffer.get() );
assertEquals( offset.getTotalSeconds(), buffer.getShort() );
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testDate() {
LocalDateTime dateTime = LocalDateTime.of(2018, 4, 10, 7, 30);
startCol.append(dateTime);
DateColumn date = startCol.date();
assertEquals(dateTime.toLocalDate(), date.get(0));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBindDateTimeWithSpecificStyle() {
DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
registrar.setDateTimeStyle(FormatStyle.MEDIUM);
setup(registrar);
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("localDateTime", LocalDateTime.of(2009, 10, 31, 12, 0));
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
String value = binder.getBindingResult().getFieldValue("localDateTime").toString();
assertTrue(value.startsWith("Oct 31, 2009"));
assertTrue(value.endsWith("12:00:00 PM"));
}
代码示例来源:origin: confluentinc/ksql
@Test
public void shouldDeserializeTimeMillisToBigint() {
shouldDeserializeTypeCorrectly(
LogicalTypes.timeMillis().addToSchema(
org.apache.avro.SchemaBuilder.builder().intType()),
ChronoUnit.MILLIS.between(
LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT),
LocalDateTime.now()),
Schema.OPTIONAL_INT64_SCHEMA
);
}
代码示例来源:origin: confluentinc/ksql
@Test
public void shouldDeserializeTimeMicrosToBigint() {
shouldDeserializeTypeCorrectly(
LogicalTypes.timeMicros().addToSchema(
org.apache.avro.SchemaBuilder.builder().longType()),
ChronoUnit.MICROS.between(
LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT),
LocalDateTime.now()),
Schema.OPTIONAL_INT64_SCHEMA
);
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testHour() {
startCol.append(LocalDateTime.of(1984, 12, 12, 7, 30));
IntColumn hour = startCol.hour();
assertEquals(7, hour.getInt(0), 0.0001);
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testDayOfWeek() {
startCol.append(LocalDateTime.of(2018, 4, 10, 7, 30));
StringColumn dayOfWeek = startCol.dayOfWeek();
assertEquals("TUESDAY", dayOfWeek.get(0));
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testMinute() {
startCol.append(LocalDateTime.of(1984, 1, 22, 7, 30));
IntColumn minute = startCol.minute();
assertEquals(30, minute.getInt(0), 0.0001);
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testHourMinute() {
startCol.append(LocalDateTime.of(2018, 4, 10, 7, 30));
StringColumn hourMinute = startCol.hourMinute();
assertEquals("07:30", hourMinute.get(0));
}
内容来源于网络,如有侵权,请联系作者删除!