本文整理了Java中java.time.LocalTime.of()
方法的一些代码示例,展示了LocalTime.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalTime.of()
方法的具体详情如下:
包路径:java.time.LocalTime
类名称:LocalTime
方法名:of
[英]Obtains an instance of LocalTime from an hour and minute.
The second and nanosecond fields will be set to zero by this factory method.
This factory may return a cached value, but applications must not rely on this.
[中]从小时和分钟获取LocalTime的实例。
第二个和纳秒字段将通过此工厂方法设置为零。
此工厂可能返回缓存值,但应用程序不能依赖于此。
代码示例来源:origin: yu199195/Raincat
/**
* 得到day的起始时间点.
* 一天开始的时间为 0:0:0
*
* @param date 短日期
* @return yyyy-MM-dd HH:mm:ss 字符串
*/
public static LocalDateTime getDayStart(final LocalDate date) {
LocalDateTime localDateTime = LocalDateTime.of(date, LocalTime.of(0, 0, 0));
return localDateTime;
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderDescendingLocalTimeArray() throws Exception
{
Object o0 = new LocalTime[]{LocalTime.of( 10, 0 )};
Object o1 = new LocalTime[]{LocalTime.of( 10, 1 )};
Object o2 = new LocalTime[]{LocalTime.of( 10, 2 )};
Object o3 = new LocalTime[]{LocalTime.of( 10, 3 )};
Object o4 = new LocalTime[]{LocalTime.of( 10, 4 )};
Object o5 = new LocalTime[]{LocalTime.of( 10, 5 )};
shouldRangeSeekInOrder( IndexOrder.DESCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderAscendingLocalTimeArray() throws Exception
{
Object o0 = new LocalTime[]{LocalTime.of( 10, 0 )};
Object o1 = new LocalTime[]{LocalTime.of( 10, 1 )};
Object o2 = new LocalTime[]{LocalTime.of( 10, 2 )};
Object o3 = new LocalTime[]{LocalTime.of( 10, 3 )};
Object o4 = new LocalTime[]{LocalTime.of( 10, 4 )};
Object o5 = new LocalTime[]{LocalTime.of( 10, 5 )};
shouldSeekInOrderExactWithRange( IndexOrder.ASCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderAscendingLocalTimeArray() throws Exception
{
Object o0 = new LocalTime[]{LocalTime.of( 10, 0 )};
Object o1 = new LocalTime[]{LocalTime.of( 10, 1 )};
Object o2 = new LocalTime[]{LocalTime.of( 10, 2 )};
Object o3 = new LocalTime[]{LocalTime.of( 10, 3 )};
Object o4 = new LocalTime[]{LocalTime.of( 10, 4 )};
Object o5 = new LocalTime[]{LocalTime.of( 10, 5 )};
shouldRangeSeekInOrder( IndexOrder.ASCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldRangeSeekInOrderDescendingLocalTimeArray() throws Exception
{
Object o0 = new LocalTime[]{LocalTime.of( 10, 0 )};
Object o1 = new LocalTime[]{LocalTime.of( 10, 1 )};
Object o2 = new LocalTime[]{LocalTime.of( 10, 2 )};
Object o3 = new LocalTime[]{LocalTime.of( 10, 3 )};
Object o4 = new LocalTime[]{LocalTime.of( 10, 4 )};
Object o5 = new LocalTime[]{LocalTime.of( 10, 5 )};
shouldSeekInOrderExactWithRange( IndexOrder.DESCENDING, o0, o1, o2, o3, o4, o5 );
}
代码示例来源:origin: prestodb/presto
public static SqlTime sqlTimeOf(
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int millisOfSecond,
Session session)
{
LocalTime time = LocalTime.of(hourOfDay, minuteOfHour, secondOfMinute, millisToNanos(millisOfSecond));
return sqlTimeOf(time, session);
}
代码示例来源:origin: neo4j/neo4j
public static LocalTimeValue localTime( int hour, int minute, int second, int nanosOfSecond )
{
return new LocalTimeValue( assertValidArgument( () -> LocalTime.of( hour, minute, second, nanosOfSecond ) ) );
}
代码示例来源:origin: neo4j/neo4j
public static TimeValue time( int hour, int minute, int second, int nanosOfSecond, ZoneOffset offset )
{
return new TimeValue(
OffsetTime.of( assertValidArgument( () -> LocalTime.of( hour, minute, second, nanosOfSecond ) ), offset ) );
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testFromToBy() {
assertContentEquals(create("times", new LocalTime[5]).fillWith(range(LocalTime.of(12, 30), // hour, minute
LocalTime.of(21, 30), 2, ChronoUnit.HOURS)), LocalTime.of(12, 30), // year, month, day, hour, minute
LocalTime.of(14, 30), LocalTime.of(16, 30), LocalTime.of(18, 30), LocalTime.of(20, 30));
}
}
代码示例来源:origin: prestodb/presto
@Test
public void testConvertTime()
throws SQLException
{
LocalTime time = LocalTime.of(12, 34, 56);
Time sqlTime = Time.valueOf(time);
java.util.Date javaDate = new java.util.Date(sqlTime.getTime());
LocalDateTime dateTime = LocalDateTime.of(LocalDate.of(2001, 5, 6), time);
Timestamp sqlTimestamp = Timestamp.valueOf(dateTime);
assertParameter(sqlTime, Types.TIME, (ps, i) -> ps.setTime(i, sqlTime));
assertParameter(sqlTime, Types.TIME, (ps, i) -> ps.setObject(i, sqlTime));
assertParameter(sqlTime, Types.TIME, (ps, i) -> ps.setObject(i, sqlTime, Types.TIME));
assertParameter(sqlTime, Types.TIME, (ps, i) -> ps.setObject(i, sqlTimestamp, Types.TIME));
assertParameter(sqlTime, Types.TIME, (ps, i) -> ps.setObject(i, javaDate, Types.TIME));
assertParameter(sqlTime, Types.TIME, (ps, i) -> ps.setObject(i, dateTime, Types.TIME));
assertParameter(sqlTime, Types.TIME, (ps, i) -> ps.setObject(i, "12:34:56", Types.TIME));
}
代码示例来源:origin: prestodb/presto
@Test
public void testConvertDate()
throws SQLException
{
LocalDate date = LocalDate.of(2001, 5, 6);
Date sqlDate = Date.valueOf(date);
java.util.Date javaDate = new java.util.Date(sqlDate.getTime());
LocalDateTime dateTime = LocalDateTime.of(date, LocalTime.of(12, 34, 56));
Timestamp sqlTimestamp = Timestamp.valueOf(dateTime);
assertParameter(sqlDate, Types.DATE, (ps, i) -> ps.setDate(i, sqlDate));
assertParameter(sqlDate, Types.DATE, (ps, i) -> ps.setObject(i, sqlDate));
assertParameter(sqlDate, Types.DATE, (ps, i) -> ps.setObject(i, sqlDate, Types.DATE));
assertParameter(sqlDate, Types.DATE, (ps, i) -> ps.setObject(i, sqlTimestamp, Types.DATE));
assertParameter(sqlDate, Types.DATE, (ps, i) -> ps.setObject(i, javaDate, Types.DATE));
assertParameter(sqlDate, Types.DATE, (ps, i) -> ps.setObject(i, date, Types.DATE));
assertParameter(sqlDate, Types.DATE, (ps, i) -> ps.setObject(i, dateTime, Types.DATE));
assertParameter(sqlDate, Types.DATE, (ps, i) -> ps.setObject(i, "2001-05-06", Types.DATE));
}
代码示例来源:origin: prestodb/presto
@Test
public void testLocallyUnrepresentableTimeLiterals()
{
LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(2017, 4, 2, 2, 10);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotExist).isEmpty(), "This test assumes certain JVM time zone");
// This tests that both Presto runner and H2 can return TIMESTAMP value that never happened in JVM's zone (e.g. is not representable using java.sql.Timestamp)
@Language("SQL") String sql = DateTimeFormatter.ofPattern("'SELECT TIMESTAMP '''uuuu-MM-dd HH:mm:ss''").format(localTimeThatDidNotExist);
assertEquals(computeScalar(sql), localTimeThatDidNotExist); // this tests Presto and the QueryRunner
assertQuery(sql); // this tests H2QueryRunner
LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1970, 1, 1);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localDateThatDidNotHaveMidnight.atStartOfDay()).isEmpty(), "This test assumes certain JVM time zone");
// This tests that both Presto runner and H2 can return DATE value for a day which midnight never happened in JVM's zone (e.g. is not exactly representable using java.sql.Date)
sql = DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(localDateThatDidNotHaveMidnight);
assertEquals(computeScalar(sql), localDateThatDidNotHaveMidnight); // this tests Presto and the QueryRunner
assertQuery(sql); // this tests H2QueryRunner
LocalTime localTimeThatDidNotOccurOn19700101 = LocalTime.of(0, 10);
checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotOccurOn19700101.atDate(LocalDate.ofEpochDay(0))).isEmpty(), "This test assumes certain JVM time zone");
checkState(!Objects.equals(java.sql.Time.valueOf(localTimeThatDidNotOccurOn19700101).toLocalTime(), localTimeThatDidNotOccurOn19700101), "This test assumes certain JVM time zone");
sql = DateTimeFormatter.ofPattern("'SELECT TIME '''HH:mm:ss''").format(localTimeThatDidNotOccurOn19700101);
assertEquals(computeScalar(sql), localTimeThatDidNotOccurOn19700101); // this tests Presto and the QueryRunner
assertQuery(sql); // this tests H2QueryRunner
}
}
代码示例来源:origin: neo4j/neo4j
@Test
void shouldGetNanosOfDayUTC()
{
LocalTime localTime = LocalTime.of( 14, 19, 18, 123999 );
ZoneOffset offset = ZoneOffset.ofHours( -12 );
OffsetTime time = OffsetTime.of( localTime, offset );
long nanosOfDayUTC = TemporalUtil.getNanosOfDayUTC( time );
long expectedNanosOfDayUTC = Duration.ofSeconds( localTime.toSecondOfDay() )
.minus( offset.getTotalSeconds(), SECONDS )
.toNanos();
assertEquals( expectedNanosOfDayUTC + localTime.getNano(), nanosOfDayUTC );
}
}
代码示例来源:origin: MorphiaOrg/morphia
@Test
public void queries() {
Instant instant = Instant.ofEpochMilli(System.currentTimeMillis());
LocalDate localDate = LocalDate.of(1995, 10, 15);
LocalDateTime localDateTime = LocalDateTime.of(2016, 4, 10, 14, 15, 16, 123 * 1000000);
LocalTime localTime = LocalTime.of(10, 29, 15, 848000000);
Java8Entity entity = createEntity(getDs(), instant, localDate, localDateTime, localTime);
compare(getDs(), entity, "instant", instant);
compare(getDs(), entity, "localDate", localDate);
compare(getDs(), entity, "localDateTime", localDateTime);
compare(getDs(), entity, "localTime", localTime);
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testHibernate() {
doInHibernate( this::sessionFactory, session -> {
Person person = new Person();
person.setId( 1L );
person.setShiftStartTime( LocalTime.of( 12, 0, 0 ) );
session.persist( person );
} );
doInHibernate( this::sessionFactory, session -> {
Person person = session.find( Person.class, 1L );
assertEquals( LocalTime.of( 12, 0, 0 ), person.getShiftStartTime() );
} );
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testOnOrAfter2() {
fillColumn();
Selection selection = column1.isOnOrAfter(LocalTime.of(7, 4, 2, 0));
assertEquals(selection.size(), 2);
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testEqual2() {
column1.appendCell("05:15:30");
column1.appendCell("10:15:30");
Selection result = column1.isEqualTo(LocalTime.of(5, 15, 30, 0));
assertEquals(result.size(), 1);
assertEquals(0, result.get(0));
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testBefore2() {
column1.appendCell("05:15:30");
column1.appendCell("10:15:30");
Selection result = column1.isBefore(LocalTime.of(7, 4, 2, 0));
assertEquals(result.size(), 1);
assertEquals(0, result.get(0));
}
代码示例来源:origin: neo4j/neo4j
private void someData( GraphDatabaseService db )
{
try ( Transaction tx = db.beginTx() )
{
db.createNode( label ).setProperty( propKey, 1 );
db.createNode( label ).setProperty( propKey, "string" );
db.createNode( label ).setProperty( propKey, Values.pointValue( Cartesian, 0.5, 0.5 ) );
db.createNode( label ).setProperty( propKey, LocalTime.of( 0, 0 ) );
tx.success();
}
}
代码示例来源:origin: jtablesaw/tablesaw
@Test
public void testAfter() {
Table t = Table.create("test");
t.addColumns(column1);
column1.appendCell("05:15:30");
column1.appendCell("10:15:30");
Table result = t.where(t.timeColumn("Game time")
.isAfter(LocalTime.of(7, 4, 2, 0)));
assertEquals(result.rowCount(), 1);
}
内容来源于网络,如有侵权,请联系作者删除!