Java 8 Time - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Time class.

This code example shows how to use the following methods:
    public void testFromBytes() 
    { 
        Assert.assertNull(accessor.fromBytes(Time.class, null));
 
        long l = System.currentTimeMillis();
        Time d = new Time(l);
        byte[] b = accessor.toBytes(d);
 
        Time d2 = accessor.fromBytes(Time.class, b);
 
        Assert.assertEquals(d, d2);
    } 
 
    /** 
     * Test method for 
     * {@link com.impetus.kundera.property.accessor.SQLTimeAccessor#toBytes(java.lang.Object)} 
     * . 
     */ 
    @Test
    public void testToBytes() 
7
CodeRank
This code example shows how to use the following methods:
public class TimeOnlyTypeHandler extends BaseTypeHandler<Date> {
 
  @Override 
  public void setNonNullParameter(PreparedStatement ps, int i, Date parameter, JdbcType jdbcType)
      throws SQLException {
    ps.setTime(i, new Time(parameter.getTime()));
  } 
 
  @Override 
  public Date getNullableResult(ResultSet rs, String columnName)
      throws SQLException {
    java.sql.Time sqlTime = rs.getTime(columnName);
    if (sqlTime != null) {
      return new Date(sqlTime.getTime());
    } 
    return null; 
  } 
 
  @Override 
  public Date getNullableResult(ResultSet rs, int columnIndex)
6
CodeRank
This code example shows how to use the following methods:
    assertEquals(calendar, result);
  } 
 
  @Test
  public void testTimeConversion() { 
    Time time = new Time(1L);
    Time result = (Time) converter.convert(Time.class, time);
    assertEquals(result, time);
  } 
 
  @Test
  public void testEmptyString() { 
    assertNull(converter.convert(Date.class, ""));
  } 
 
  @Test
  public void testGoodString() { 
    GregorianCalendar calendar = new GregorianCalendar(2001, 1, 1);
    java.util.Date expected = calendar.getTime();
    assertEquals(expected, converter.convert(java.util.Date.class, "01.02.2001"));
6
CodeRank
This code example shows how to use the following methods:
 
        if (dateAsString.length() != dateFormat.toPattern().length() && dateAsString.length() != timeFormat.toPattern().length()) { //subtract 2 to not count the 's
            return new java.sql.Timestamp(dateTimeFormat.parse(dateAsString).getTime());
        } else { 
            if (dateAsString.indexOf(':') > 0) {
                return new java.sql.Time(timeFormat.parse(dateAsString).getTime());
            } else { 
                return new java.sql.Date(dateFormat.parse(dateAsString).getTime());
            } 
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:toString, getTime
This code example shows how to use the following methods:
    } 
 
    @Override 
    public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
        cal.setTime(x);
        parameters.set(parameterIndex - 1, new Time(cal.getTimeInMillis()));
    } 
 
    @Override 
    public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
        parameters.set(parameterIndex - 1, x);
    } 
 
    @Override 
    public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
        cal.setTime(x);
        parameters.set(parameterIndex - 1,  DateUtil.getTimestamp(cal.getTimeInMillis(), x.getNanos()));
    } 
 
    @Override 
6
CodeRank
This code example shows how to use the following methods:
 
public class Datetime2SqlTime extends Castor<Date, Time> {
 
    @Override 
    public Time cast(Date src, Class<?> toType, String... args) throws FailToCastObjectException {
        return new Time(src.getTime());
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:getHours, getMinutes, getSeconds
            //null time getHasValue only for defaults 
            Date now = new Date();
            t = new Time(now.getHours(), 0, 0);
        } 
 
        return t.getHours() * 10000 + t.getMinutes() * 100 + t.getSeconds();
    } 
 
    public Time IntToTime(Integer time) {
        Integer seconds = time % 100;
 
        time = (time - seconds) / 100;
 
        Integer minutes = time % 100;
        Integer hours = (time - minutes) / 100;
 
        Time t = new Time(hours, minutes, seconds);
 
        return t;
    } 
6
CodeRank
This code example shows how to use the following methods:getHours, getMinutes, getSeconds
   * @param time  the SQL time to convert, not null 
   * @return the time, not null 
   */ 
  @SuppressWarnings("deprecation") 
  public static LocalTime fromSqlTime(Time time) {
    ArgumentChecker.notNull(time, "time");
    return LocalTime.of(time.getHours(), time.getMinutes(), time.getSeconds());
  } 
 
  /** 
   * Creates a {@code LocalTime} from an SQL timestamp. 
   * <p> 
   * This method is needed to be able to retrieve nanoseconds from the database when dealing with times. 
   *  
   * @param timestamp  the SQL timestamp to convert, not null 
   * @return the time, not null 
   */ 
  @SuppressWarnings("deprecation") 
  public static LocalTime fromSqlTime(Timestamp timestamp) {
    ArgumentChecker.notNull(timestamp, "timestamp");
6
CodeRank
This code example shows how to use the following methods:
public class Timestamp2SqlTime extends Castor<Timestamp, Time> {
 
    @Override 
    public Time cast(Timestamp src, Class<?> toType, String... args)
            throws FailToCastObjectException { 
        return new Time(src.getTime());
    } 
 
} 
6
CodeRank
See Code Examples for Java 8 Time Methods: