List of usage examples for java.sql Timestamp getTime
public long getTime()
From source file:org.apache.hadoop.hive.serde2.io.TimestampWritable.java
/** * Writes a Timestamp's serialized value to byte array b at * @param t//from w ww . j a v a2s . c om * @param b */ public static void convertTimestampToBytes(Timestamp t, byte[] b, int offset) { if (b.length < 9) { LOG.error("byte array too short"); } long millis = t.getTime(); int nanos = t.getNanos(); boolean hasDecimal = nanos != 0 && setNanosBytes(nanos, b, offset + 4); setSecondsBytes(millis, b, offset, hasDecimal); }
From source file:com.arm.connector.bridge.core.Utils.java
public static String dateToString(java.sql.Timestamp timestamp) { if (timestamp != null) { return Utils.dateToString(new java.util.Date(timestamp.getTime())); } else {//w w w . ja v a2s.c o m return "[no date]"; } }
From source file:org.apereo.portal.concurrency.locking.RDBMEntityLockStore.java
/** * @return long/* ww w . j a v a 2 s .co m*/ */ private static long getTimestampMillis(Timestamp ts) { if (timestampHasMillis) { return ts.getTime(); } else { return (ts.getTime() + ts.getNanos() / 1000000); } }
From source file:com.clustercontrol.jobmanagement.util.JobKickFilterPropertyUtil.java
/** * DTO?????/*from w w w . j av a 2s . c o m*/ * * @param property * @return */ public static JobKickFilterInfo property2dto(Property property) { JobKickFilterInfo info = new JobKickFilterInfo(); ArrayList<?> values = null; // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBKICK_ID); if (!"".equals(values.get(0))) { info.setJobkickId((String) values.get(0)); } // ?? values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBKICK_NAME); if (!"".equals(values.get(0))) { info.setJobkickName((String) values.get(0)); } // values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBKICK_TYPE); if (!"".equals(values.get(0))) { info.setJobkickType((Integer) JobKickTypeMessage.stringToType((String) values.get(0))); } // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOBUNIT_ID); if (!"".equals(values.get(0))) { info.setJobunitId((String) values.get(0)); } // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.JOB_ID); if (!"".equals(values.get(0))) { info.setJobId((String) values.get(0)); } // ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.CALENDAR_ID); if (!"".equals(values.get(0))) { info.setCalendarId((String) values.get(0)); } // Boolean validFlg = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.VALID_FLG); if (!"".equals(values.get(0))) { if (ValidMessage.STRING_VALID.equals(values.get(0))) { validFlg = true; } else { validFlg = false; } } info.setValidFlg(validFlg); //?? values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.REG_USER); if (!"".equals(values.get(0))) { info.setRegUser((String) values.get(0)); } //?(From) Timestamp regFromDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.REG_FROM_DATE); if (values.get(0) instanceof Date) { regFromDate = new Timestamp(((Date) values.get(0)).getTime()); regFromDate.setNanos(999999999); info.setRegFromDate(regFromDate.getTime()); } //?(To) Timestamp regToDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.REG_TO_DATE); if (values.get(0) instanceof Date) { regToDate = new Timestamp(((Date) values.get(0)).getTime()); regToDate.setNanos(999999999); info.setRegToDate(regToDate.getTime()); } // values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.UPDATE_USER); if (!"".equals(values.get(0))) { info.setUpdateUser((String) values.get(0)); } //(From) Timestamp updateFromDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.UPDATE_FROM_DATE); if (values.get(0) instanceof Date) { updateFromDate = new Timestamp(((Date) values.get(0)).getTime()); updateFromDate.setNanos(999999999); info.setUpdateFromDate(updateFromDate.getTime()); } //(To) Timestamp updateToDate = null; values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.UPDATE_TO_DATE); if (values.get(0) instanceof Date) { updateToDate = new Timestamp(((Date) values.get(0)).getTime()); updateToDate.setNanos(999999999); info.setUpdateToDate(updateToDate.getTime()); } //ID values = PropertyUtil.getPropertyValue(property, JobKickFilterConstant.OWNER_ROLE_ID); if (!"".equals(values.get(0))) { info.setOwnerRoleId((String) values.get(0)); } return info; }
From source file:adalid.commons.util.TimeUtils.java
public static java.util.Date newUtilDate(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute) { Timestamp t = newTimestamp(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute); return new java.util.Date(t.getTime()); }
From source file:com.etcc.csc.datatype.PaymentDetailUtil.java
public static Calendar timestampToCalendar(Timestamp timestamp) { if (timestamp == null) { return null; }/*from w ww .j a v a2s.com*/ Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date(timestamp.getTime())); return calendar; }
From source file:org.apereo.portal.security.provider.RDBMPermissionImpl.java
/** * @return long// w w w . j a va2 s . com */ private static long getTimestampMillis(Timestamp ts) { return ts.getTime(); }
From source file:de.fraunhofer.iosb.ilt.sta.persistence.postgres.PropertyHelper.java
private static TimeInstant instantFromTime(Timestamp time) { if (time == null) { return new TimeInstant(null); }//from ww w .j a v a2 s. c o m return TimeInstant.create(time.getTime()); }
From source file:org.latticesoft.util.common.DateUtil.java
/** * Get a random timestamp/*from w w w .ja v a2s . c om*/ */ public static Timestamp getRandomTimestamp(Timestamp start, Timestamp end) { Timestamp ts = null; if (start == null || end == null) { ts = new Timestamp(System.currentTimeMillis()); } else { long startTime = start.getTime(); long endTime = end.getTime(); long randomTime = NumeralUtil.getRandomLong(startTime, endTime); ts = new Timestamp(randomTime); } return ts; }
From source file:org.moqui.impl.entity.EntityJavaUtil.java
public static Object convertFromString(String value, FieldInfo fi, L10nFacade l10n) { Object outValue;/*from w w w.j a va2 s .c o m*/ boolean isEmpty = value.length() == 0; try { switch (fi.typeValue) { case 1: outValue = value; break; case 2: // outValue = java.sql.Timestamp.valueOf(value); if (isEmpty) { outValue = null; break; } outValue = l10n.parseTimestamp(value, null); if (outValue == null) throw new BaseException("The value [" + value + "] is not a valid date/time for field " + fi.entityName + "." + fi.name); break; case 3: // outValue = java.sql.Time.valueOf(value); if (isEmpty) { outValue = null; break; } outValue = l10n.parseTime(value, null); if (outValue == null) throw new BaseException("The value [" + value + "] is not a valid time for field " + fi.entityName + "." + fi.name); break; case 4: // outValue = java.sql.Date.valueOf(value); if (isEmpty) { outValue = null; break; } outValue = l10n.parseDate(value, null); if (outValue == null) throw new BaseException("The value [" + value + "] is not a valid date for field " + fi.entityName + "." + fi.name); break; case 5: // outValue = Integer.valueOf(value); break case 6: // outValue = Long.valueOf(value); break case 7: // outValue = Float.valueOf(value); break case 8: // outValue = Double.valueOf(value); break case 9: // outValue = new BigDecimal(value); break if (isEmpty) { outValue = null; break; } BigDecimal bdVal = l10n.parseNumber(value, null); if (bdVal == null) { throw new BaseException("The value [" + value + "] is not valid for type [" + fi.javaType + "] for field " + fi.entityName + "." + fi.name); } else { bdVal = bdVal.stripTrailingZeros(); switch (fi.typeValue) { case 5: outValue = bdVal.intValue(); break; case 6: outValue = bdVal.longValue(); break; case 7: outValue = bdVal.floatValue(); break; case 8: outValue = bdVal.doubleValue(); break; default: outValue = bdVal; break; } } break; case 10: if (isEmpty) { outValue = null; break; } outValue = Boolean.valueOf(value); break; case 11: outValue = value; break; case 12: try { outValue = new SerialBlob(value.getBytes()); } catch (SQLException e) { throw new BaseException("Error creating SerialBlob for value [" + value + "] for field " + fi.entityName + "." + fi.name); } break; case 13: outValue = value; break; case 14: if (isEmpty) { outValue = null; break; } Timestamp ts = l10n.parseTimestamp(value, null); outValue = new java.util.Date(ts.getTime()); break; // better way for Collection (15)? maybe parse comma separated, but probably doesn't make sense in the first place case 15: outValue = value; break; default: outValue = value; break; } } catch (IllegalArgumentException e) { throw new BaseException("The value [" + value + "] is not valid for type [" + fi.javaType + "] for field " + fi.entityName + "." + fi.name, e); } return outValue; }