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


Java Time.valueOf方法代码示例

本文整理汇总了Java中java.sql.Time.valueOf方法的典型用法代码示例。如果您正苦于以下问题:Java Time.valueOf方法的具体用法?Java Time.valueOf怎么用?Java Time.valueOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.Time的用法示例。


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

示例1: test10

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test10() {
    LocalTime lt = LocalTime.of(8, 30, 59);
    Time t = Time.valueOf(lt);
    System.out.println("lt=" + lt + ",t=" + t.toLocalTime());
    assertTrue(lt.equals(t.toLocalTime()),
            "Error LocalTime values are not equal");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TimeTests.java

示例2: test13

import java.sql.Time; //导入方法依赖的package包/类
@Test(dataProvider = "validTimeValues")
public void test13(String time, String expected) {
    Time t1 = Time.valueOf(time);
    Time t2 = Time.valueOf(t1.toString());
    assertTrue(t1.equals(t2) && t2.equals(t1)
            && t1.toString().equals(expected), "Error t1 != t2");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TimeTests.java

示例3: convertJavaTimeToJavaSql

import java.sql.Time; //导入方法依赖的package包/类
/**
 * JDBC 4.2 Helper methods.
 */
static Object convertJavaTimeToJavaSql(Object x) {
    if (x instanceof LocalDate) {
        return Date.valueOf((LocalDate) x);
    } else if (x instanceof LocalDateTime) {
        return Timestamp.valueOf((LocalDateTime) x);
    } else if (x instanceof LocalTime) {
        return Time.valueOf((LocalTime) x);
    }
    return x;
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:14,代码来源:JDBC42Helper.java

示例4: timeValue

import java.sql.Time; //导入方法依赖的package包/类
/**
 * Converts a string in JDBC date escape format to a
 * <code>Time</code> value.
 *
 * @param s date in format <code>hh:mm:ss</code>
 * @return  corresponding <code>Time</code> value
 * @exception java.lang.IllegalArgumentException if the given argument
 * does not have the format <code>hh:mm:ss</code>
 */
public static Time timeValue(String s) {

    if (s == null) {
        throw new java.lang.IllegalArgumentException(
            Trace.getMessage(Trace.HsqlDateTime_null_string));
    }

    return Time.valueOf(s);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:19,代码来源:HsqlDateTime.java

示例5: test01

import java.sql.Time; //导入方法依赖的package包/类
@Test(expectedExceptions = IllegalArgumentException.class)
public void test01() {
    Time t = Time.valueOf("08:30:59");
    t.getYear();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TimeTests.java

示例6: test21

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test21() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(System.currentTimeMillis());
    assertTrue(t.before(t2), "Error t.before(t2) = false");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:TimeTests.java

示例7: test02

import java.sql.Time; //导入方法依赖的package包/类
@Test(expectedExceptions = IllegalArgumentException.class)
public void test02() {
    Time t = Time.valueOf("08:30:59");
    t.getMonth();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TimeTests.java

示例8: test14

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test14() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = new Time(8, 30, 59);
    assertTrue(t.equals(t2) && t2.equals(t), "Error t != t2");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:TimeTests.java

示例9: fromString

import java.sql.Time; //导入方法依赖的package包/类
@Override
public Object fromString(final String str) {
    return Time.valueOf(str);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:SqlTimeConverter.java

示例10: test16

import java.sql.Time; //导入方法依赖的package包/类
@Test(dataProvider = "invalidTimeValues",
        expectedExceptions = IllegalArgumentException.class)
public void test16(String time) throws Exception {
    Time.valueOf(time);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TimeTests.java

示例11: testTimeComplex

import java.sql.Time; //导入方法依赖的package包/类
public void testTimeComplex() {
    PreparedStatement ps = null;
    ResultSet rs = null;
    Time aTime = Time.valueOf("21:19:27");

    try {
        ps = netConn.prepareStatement(
            "INSERT INTO alltypes(id, t) VALUES(?, ?)");
        ps.setInt(1, 3);
        ps.setTime(2, aTime);
        assertEquals(1, ps.executeUpdate());
        ps.setInt(1, 4);
        assertEquals(1, ps.executeUpdate());
        ps.close();
        netConn.commit();
        ps = netConn.prepareStatement(
            "SELECT * FROM alltypes WHERE t = ?");
        ps.setTime(1, aTime);
        rs = ps.executeQuery();
        assertTrue("Got no rows with t = aTime", rs.next());
        assertEquals(Time.class, rs.getObject("t").getClass());
        assertTrue("Got only one row with t = aTime", rs.next());
        assertEquals(aTime, rs.getTime("t"));
        assertFalse("Got too many rows with t = aTime", rs.next());
    } catch (SQLException se) {
        junit.framework.AssertionFailedError ase
            = new junit.framework.AssertionFailedError(se.getMessage());
        ase.initCause(se);
        throw ase;
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (ps != null) {
                ps.close();
            }
        } catch(Exception e) {
        }
    }
}
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:42,代码来源:TestOdbcTypes.java

示例12: testBaseParameters

import java.sql.Time; //导入方法依赖的package包/类
@DataProvider(name = "testBaseParameters")
private Object[][] testBaseParameters() throws SQLException {
    Integer aInt = 1;
    Long aLong = Long.MAX_VALUE;
    Short aShort = Short.MIN_VALUE;
    BigDecimal bd = BigDecimal.ONE;
    Double aDouble = Double.MAX_VALUE;
    Date aDate = Date.valueOf(LocalDate.now());
    Time aTime = Time.valueOf(LocalTime.now());
    Timestamp aTimeStamp = Timestamp.valueOf(LocalDateTime.now());
    Calendar cal = Calendar.getInstance();
    Boolean aBoolean = true;
    Float aFloat = 1.5f;
    Byte aByte = 1;
    brs = new StubBaseRowSet();

    brs.setInt(1, aInt);
    brs.setString(2, query);
    brs.setLong(3, aLong);
    brs.setBoolean(4, aBoolean);
    brs.setShort(5, aShort);
    brs.setDouble(6, aDouble);
    brs.setBigDecimal(7, bd);
    brs.setFloat(8, aFloat);
    brs.setByte(9, aByte);
    brs.setDate(10, aDate);
    brs.setTime(11, aTime);
    brs.setTimestamp(12, aTimeStamp);
    brs.setDate(13, aDate, cal);
    brs.setTime(14, aTime, cal);
    brs.setTimestamp(15, aTimeStamp);
    brs.setObject(16, query);
    brs.setObject(17, query, Types.CHAR);
    brs.setObject(18, query, Types.CHAR, 0);

    return new Object[][]{
        {1, aInt},
        {2, query},
        {3, aLong},
        {4, aBoolean},
        {5, aShort},
        {6, aDouble},
        {7, bd},
        {8, aFloat},
        {9, aByte},
        {10, aDate},
        {11, aTime},
        {12, aTimeStamp},
        {13, aDate},
        {14, aTime},
        {15, aTimeStamp},
        {16, query},
        {17, query},
        {18, query}

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

示例13: test23

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test23() {
    Time t = Time.valueOf("08:30:59");
    assertTrue(t.compareTo(t) == 0, "Error t.compareTo(t) !=0");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TimeTests.java

示例14: test20

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test20() {
    Time t = Time.valueOf("08:30:59");
    assertFalse(t.before(t), "Error t.before(t) = true");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:TimeTests.java

示例15: test09

import java.sql.Time; //导入方法依赖的package包/类
@Test
public void test09() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = Time.valueOf(t.toLocalTime());
    assertTrue(t.equals(t2), "Error t != t2");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TimeTests.java


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