Tabnine Logo
Time
Code IndexAdd Tabnine to your IDE (free)

How to use
Time
in
java.sql

Best Java code snippets using java.sql.Time (Showing top 20 results out of 18,639)

Refine searchRefine arrow

  • Date
  • Timestamp
  • Date
  • Calendar
  • BigDecimal
origin: hibernate/hibernate-orm

@SuppressWarnings({ "unchecked" })
public <X> X unwrap(Calendar value, Class<X> type, WrapperOptions options) {
  if ( value == null ) {
    return null;
  }
  if ( Calendar.class.isAssignableFrom( type ) ) {
    return (X) value;
  }
  if ( java.sql.Date.class.isAssignableFrom( type ) ) {
    return (X) new java.sql.Date( value.getTimeInMillis() );
  }
  if ( java.sql.Time.class.isAssignableFrom( type ) ) {
    return (X) new java.sql.Time( value.getTimeInMillis() );
  }
  if ( java.sql.Timestamp.class.isAssignableFrom( type ) ) {
    return (X) new java.sql.Timestamp( value.getTimeInMillis() );
  }
  if ( Date.class.isAssignableFrom( type ) ) {
    return (X) new  Date( value.getTimeInMillis() );
  }
  throw unknownUnwrap( type );
}
origin: redisson/redisson

  return new Time(((Calendar) value).getTimeInMillis());
  return new Time(((Date)value).getTime());
  return new Time(((Number) value).longValue());
    return Time.valueOf(stringValue);
  } catch (IllegalArgumentException iaex) {
    throw new TypeConversionException(value, iaex);
  return new Time(milliseconds);
} catch (NumberFormatException nfex) {
  throw new TypeConversionException(value, nfex);
origin: nutzam/nutz

@Override
public Timestamp cast(Time src, Class<?> toType, String... args)
    throws FailToCastObjectException {
  return new Timestamp(src.getTime());
}
origin: apache/flink

@Override
public Time copy(Time from) {
  if (from == null) {
    return null;
  }
  return new Time(from.getTime());
}
origin: apache/flink

@Override
public Time copy(Time from, Time reuse) {
  if (from == null) {
    return null;
  }
  reuse.setTime(from.getTime());
  return reuse;
}
origin: apache/geode

private String getFileNamePrefix() {
 String timeStamp = new java.sql.Time(System.currentTimeMillis()).toString();
 timeStamp = timeStamp.replace(':', '_');
 return fileNamePrefix + "-" + timeStamp;
}
origin: apache/incubator-dubbo

  return new BigInteger(string);
} else if (type == BigDecimal.class) {
  return new BigDecimal(string);
} else if (type == Short.class || type == short.class) {
  return new Short(string);
    Date date = new SimpleDateFormat(DATE_FORMAT).parse((String) value);
    if (type == java.sql.Date.class) {
      return new java.sql.Date(date.getTime());
    } else if (type == java.sql.Timestamp.class) {
      return new java.sql.Timestamp(date.getTime());
    } else if (type == java.sql.Time.class) {
      return new java.sql.Time(date.getTime());
    } else {
      return date;
  return BigInteger.valueOf(number.longValue());
} else if (type == BigDecimal.class) {
  return BigDecimal.valueOf(number.doubleValue());
} else if (type == Date.class) {
  return new Date(number.longValue());
origin: apache/incubator-shardingsphere

  private static Object convertDateValue(final Object value, final Class<?> convertType) {
    Date date = (Date) value;
    switch (convertType.getName()) {
      case "java.sql.Date":
        return new java.sql.Date(date.getTime());
      case "java.sql.Time":
        return new Time(date.getTime());
      case "java.sql.Timestamp":
        return new Timestamp(date.getTime());
      default:
        throw new ShardingException("Unsupported Date type:%s", convertType);
    }
  }
}
origin: apache/ignite

/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
  startGridsMultiThreaded(3);
  IgniteCache<Integer, TestObject> cache = grid(0).cache(DEFAULT_CACHE_NAME);
  assert cache != null;
  TestObject o = new TestObject(1);
  o.boolVal = true;
  o.byteVal = 1;
  o.shortVal = 1;
  o.intVal = 1;
  o.longVal = 1L;
  o.floatVal = 1.0f;
  o.doubleVal = 1.0d;
  o.bigVal = new BigDecimal(1);
  o.strVal = "str";
  o.arrVal = new byte[] {1};
  o.dateVal = new Date(1);
  o.timeVal = new Time(1);
  o.tsVal = new Timestamp(1);
  o.urlVal = new URL("http://abc.com/");
  cache.put(1, o);
  cache.put(2, new TestObject(2));
}
origin: prestodb/presto

@Test
public void testTime()
    throws Exception
{
  AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance();
  Type type = TIME;
  Time expected = new Time(new java.util.Date().getTime());
  byte[] data = serializer.encode(type, expected);
  Time actual = new Time(serializer.decode(type, data));
  assertEquals(actual, expected);
  deserializeData(serializer, data);
  actual = serializer.getTime(COLUMN_NAME);
  assertEquals(actual, expected);
}
origin: commons-beanutils/commons-beanutils

return type.cast(new Date(value));
return type.cast(new java.sql.Date(value));
return type.cast(new java.sql.Time(value));
return type.cast(new java.sql.Timestamp(value));
Calendar calendar = null;
if (locale == null && timeZone == null) {
  calendar = Calendar.getInstance();
} else if (locale == null) {
  calendar = Calendar.getInstance(timeZone);
} else if (timeZone == null) {
  calendar = Calendar.getInstance(locale);
} else {
  calendar = Calendar.getInstance(timeZone, locale);
calendar.setTime(new Date(value));
calendar.setLenient(false);
return type.cast(calendar);
origin: macrozheng/mall

protected void addCriterionForJDBCTime(String condition, Date value1, Date value2, String property) {
  if (value1 == null || value2 == null) {
    throw new RuntimeException("Between values for " + property + " cannot be null");
  }
  addCriterion(condition, new java.sql.Time(value1.getTime()), new java.sql.Time(value2.getTime()), property);
}
origin: apache/incubator-shardingsphere

@Override
public void write(final MySQLPacketPayload payload, final Object value) {
  Calendar calendar = Calendar.getInstance();
  calendar.setTimeInMillis(((Time) value).getTime());
  int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
  int minutes = calendar.get(Calendar.MINUTE);
  int seconds = calendar.get(Calendar.SECOND);
  int nanos = new Timestamp(calendar.getTimeInMillis()).getNanos();
  boolean isTimeAbsent = 0 == hourOfDay && 0 == minutes && 0 == seconds;
  boolean isNanosAbsent = 0 == nanos;
  if (isTimeAbsent && isNanosAbsent) {
    payload.writeInt1(0);
    return;
  }
  if (isNanosAbsent) {
    payload.writeInt1(8);
    writeTime(payload, hourOfDay, minutes, seconds);
    return;
  }
  payload.writeInt1(12);
  writeTime(payload, hourOfDay, minutes, seconds);
  writeNanos(payload, nanos);
}

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: spring-projects/spring-framework

@Test
public void testSetParameterValueWithTimeAndUtilDate() throws SQLException {
  java.util.Date date = new java.util.Date(1000);
  StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.TIME, null, date);
  verify(preparedStatement).setTime(1, new java.sql.Time(1000));
}
origin: spring-projects/spring-framework

@Test
public void testSetParameterValueWithTimeAndCalendar() throws SQLException {
  java.util.Calendar cal = new GregorianCalendar();
  StatementCreatorUtils.setParameterValue(preparedStatement, 1, Types.TIME, null, cal);
  verify(preparedStatement).setTime(1, new java.sql.Time(cal.getTime().getTime()), cal);
}
origin: hibernate/hibernate-orm

  @Override
  public <X> Date wrap(X value, WrapperOptions options) {
    if ( value == null ) {
      return null;
    }
    if ( Time.class.isInstance( value ) ) {
      return (Time) value;
    }

    if ( Long.class.isInstance( value ) ) {
      return new Time( (Long) value );
    }

    if ( Calendar.class.isInstance( value ) ) {
      return new Time( ( (Calendar) value ).getTimeInMillis() );
    }

    if ( Date.class.isInstance( value ) ) {
      return new Time( ( (Date) value ).getTime() );
    }

    throw unknownWrap( value.getClass() );
  }
}
origin: hibernate/hibernate-orm

  public String objectToSQLString(Date value, Dialect dialect) throws Exception {
    Time jdbcTime = Time.class.isInstance( value )
        ? ( Time ) value
        : new Time( value.getTime() );
    // TODO : use JDBC time literal escape syntax? -> {t 'time-string'} in hh:mm:ss format
    return StringType.INSTANCE.objectToSQLString( jdbcTime.toString(), dialect );
  }
}
origin: querydsl/querydsl

  @Test
  public void test() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 13);
    cal.set(Calendar.MINUTE,      30);
    cal.set(Calendar.SECOND,      12);
    cal.set(Calendar.MILLISECOND,  3);

    TimeExpression<Time> time = TimeConstant.create(new Time(cal.getTimeInMillis()));
    assertEquals("13",   time.hour().toString());
    assertEquals("30",   time.minute().toString());
    assertEquals("12",   time.second().toString());
//        assertEquals("3",    time.getMilliSecond().toString());
  }

origin: oblac/jodd

@Test
void testCalendar2Timestamp() {
  Calendar calendar = Calendar.getInstance();
  calendar.setTimeInMillis(time);
  Time sqltime = sqlTimeConverter.convert(calendar);
  assertEquals(time, sqltime.getTime());
}
java.sqlTime

Javadoc

Java representation of an SQL TIME value. Provides utilities to format and parse the time's representation as a String in JDBC escape format.

Most used methods

  • <init>
    Constructs a Time object using a supplied time specified in milliseconds.
  • valueOf
  • getTime
  • toString
    Formats the Time as a String in JDBC escape format: hh:mm:ss.
  • toLocalTime
  • getHours
  • getMinutes
  • getSeconds
  • setTime
    Sets the time for this Time object to the supplied milliseconds value.
  • compareTo
  • equals
  • format
  • equals,
  • format,
  • before,
  • clone,
  • from,
  • hashCode,
  • after,
  • setDate,
  • setHours,
  • setMinutes

Popular in Java

  • Start an intent from android
  • getSupportFragmentManager (FragmentActivity)
  • getSharedPreferences (Context)
  • scheduleAtFixedRate (Timer)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now