List of usage examples for java.sql Timestamp getTime
public long getTime()
From source file:fr.ericlab.mabed.structure.Corpus.java
public Timestamp toDate(int timeSlice) { Timestamp date = startTimestamp; long dateLong = date.getTime() + timeSlice * configuration.timeSliceLength * 60 * 1000L; return new Timestamp(dateLong); }
From source file:org.openmrs.contrib.metadatarepository.util.DateConverterTest.java
public void testConvertStringToTimestamp() throws Exception { final Date today = new Date(); final Calendar todayCalendar = new GregorianCalendar(); todayCalendar.setTime(today);//w w w . j a v a 2 s. c o m final String datePart = DateUtil.convertDateToString(today); final Timestamp time = (Timestamp) converter.convert(Timestamp.class, datePart + " 01:02:03.4"); final Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(time.getTime()); assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR)); assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH)); assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH)); }
From source file:de.ks.idnadrev.expimp.xls.XlsxExporterTest.java
@Test public void testExportThoughts() throws Exception { File tempFile = File.createTempFile("thoughtExport", ".xlsx"); EntityExportSource<Thought> source = new EntityExportSource<>(getAllIds(), Thought.class); XlsxExporter exporter = new XlsxExporter(); exporter.export(tempFile, source);//from w w w. ja va 2 s .c o m Workbook wb = WorkbookFactory.create(tempFile); Sheet sheet = wb.getSheetAt(0); assertEquals(Thought.class.getName(), sheet.getSheetName()); int lastRowNum = sheet.getLastRowNum(); assertEquals(COUNT, lastRowNum); Row firstRow = sheet.getRow(0); ArrayList<String> titles = new ArrayList<>(); firstRow.cellIterator().forEachRemaining(col -> titles.add(col.getStringCellValue())); assertThat(titles.size(), greaterThanOrEqualTo(3)); log.info("Found titles {}", titles); String creationTime = PropertyPath.property(Thought.class, t -> t.getCreationTime()); String name = PropertyPath.property(Thought.class, t -> t.getName()); String description = PropertyPath.property(Thought.class, t -> t.getDescription()); assertTrue(titles.contains(creationTime)); assertTrue(titles.contains(name)); assertTrue(titles.contains(description)); int nameColumn = titles.indexOf(name); ArrayList<String> names = new ArrayList<String>(COUNT); for (int i = 1; i <= COUNT; i++) { Row row = sheet.getRow(i); names.add(row.getCell(nameColumn).getStringCellValue()); } Collections.sort(names); assertEquals("Thought000", names.get(0)); assertEquals("Thought141", names.get(COUNT - 1)); Date excelDate = sheet.getRow(1).getCell(titles.indexOf(creationTime)).getDateCellValue(); Thought thought = PersistentWork.forName(Thought.class, "Thought000"); Timestamp timestamp = java.sql.Timestamp.valueOf(thought.getCreationTime()); Date creationDate = new Date(timestamp.getTime()); assertEquals(creationDate, excelDate); }
From source file:ru.org.linux.comment.CommentDaoIntegrationTest.java
@Test public void updateLatestEditorInfoTest() { int commentId = jdbcTemplate.queryForInt("select nextval('s_msgid')"); try {//from w w w . j ava2 s .com addComment(commentId, null, "CommentDaoIntegrationTest.updateLatestEditorInfoTest()", "comment body"); List<Map<String, Object>> rows = getComment(commentId); assertFalse("No any records", rows.isEmpty()); Map<String, Object> row = rows.get(0); assertNull(row.get("edit_nick")); assertNull(row.get("edit_date")); assertEquals(0, row.get("edit_count")); Date commentEditDate = new Date(); commentDao.updateLatestEditorInfo(commentId, 1, commentEditDate, 1234); rows = getComment(commentId); assertFalse("No any records", rows.isEmpty()); row = rows.get(0); Timestamp rowTimestamp = (Timestamp) row.get("edit_date"); assertEquals("maxcom", row.get("edit_nick")); assertEquals(rowTimestamp.getTime(), commentEditDate.getTime()); assertEquals(1234, row.get("edit_count")); } finally { delComment(commentId); } }
From source file:org.bahmni.feed.openelis.feed.service.impl.AccessionService.java
private String toISODateFormat(Timestamp timestamp) { return DateFormatUtils.format(timestamp.getTime(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()); }
From source file:edu.utah.further.mdr.data.common.domain.asset.ActivationInfoEntity.java
/** * @param other//from w w w.j av a 2 s .c om * @return * @see edu.utah.further.mdr.api.domain.asset.ActivationInfo#copyFrom(edu.utah.further.mdr.api.domain.asset.ActivationInfo) */ @Override public ActivationInfoEntity copyFrom(final ActivationInfo other) { if (other == null) { return this; } // Identifier is not copied // Deep-copy fields final Timestamp otherActivationDate = other.getActivationDate(); if (otherActivationDate != null) { this.activationDate = new Timestamp(otherActivationDate.getTime()); } final Timestamp otherDeactivationDate = other.getDeactivationDate(); if (otherDeactivationDate != null) { this.deactivationDate = new Timestamp(otherDeactivationDate.getTime()); } // Deep-copy collection references but soft-copy their elements return this; }
From source file:nl.b3p.commons.taglib.WriteDateTag.java
/** * Process the start tag./*w w w . j ava 2 s . c o m*/ * * @exception JspException if a JSP exception has occurred */ public int doStartTag() throws JspException { // Look up the requested bean Object value = null; if (name != null) { // er zou een datum te vinden moeten zijn if (TagUtils.getInstance().lookup(pageContext, name, scope) == null) { return (SKIP_BODY); // Nothing to output // Look up the requested property value } value = TagUtils.getInstance().lookup(pageContext, name, property, scope); } if (value == null) { // een voorbeeld datum met locale wordt afgedrukt Date exValue = new Date(); value = exValue; } // Get locale of this request for date printing HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); Locale locale = request.getLocale(); // Print this property value to our output writer String output = null; if (value != null) { if (value instanceof Date) { output = FormUtils.DateToString((Date) value, locale); if (log.isDebugEnabled()) { log.debug("Date: " + output); } } else if (value instanceof Timestamp) { Timestamp temptime = (Timestamp) value; Date tempdate = new Date(); tempdate.setTime(temptime.getTime()); output = FormUtils.DateToString(tempdate, locale); if (log.isDebugEnabled()) { log.debug("Timestamp: " + output); } } else if (value instanceof String) { SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance(); sdf.applyPattern("yyyy-MM-dd HH:mm"); Date tempdate = null; try { tempdate = sdf.parse((String) value); output = FormUtils.DateToString(tempdate, locale); if (log.isDebugEnabled()) { log.debug("String (yyyy-MM-dd HH:mm): " + output); } } catch (java.text.ParseException pe) { output = ((String) value).trim(); int spacedex = output.indexOf(' '); if (spacedex > 1) { output = output.substring(0, spacedex); } if (log.isDebugEnabled()) { log.debug("No conversion: " + output); } } } } TagUtils.getInstance().write(pageContext, output); // Continue processing this page return (SKIP_BODY); }
From source file:org.apdplat.superword.tools.MySQLUtils.java
public static List<UserSimilarWord> getHistoryUserSimilarWordsFromDatabase(String userName) { List<UserSimilarWord> userSimilarWords = new ArrayList<>(); String sql = "select id,similar_word,date_time from user_similar_word where user_name=?"; Connection con = getConnection(); if (con == null) { return userSimilarWords; }/* w ww . j a v a 2 s. c o m*/ PreparedStatement pst = null; ResultSet rs = null; try { pst = con.prepareStatement(sql); pst.setString(1, userName); rs = pst.executeQuery(); while (rs.next()) { int id = rs.getInt(1); String similarWord = rs.getString(2); Timestamp timestamp = rs.getTimestamp(3); UserSimilarWord userSimilarWord = new UserSimilarWord(); userSimilarWord.setId(id); userSimilarWord.setSimilarWord(similarWord); userSimilarWord.setDateTime(new java.util.Date(timestamp.getTime())); userSimilarWord.setUserName(userName); userSimilarWords.add(userSimilarWord); } } catch (SQLException e) { LOG.error("", e); } finally { close(con, pst, rs); } return userSimilarWords; }
From source file:net.ymate.platform.module.search.support.SearchHelper.java
public SearchHelper<T> query(String field, Timestamp begin, Timestamp end) { long beginTime = begin.getTime(); long endTime = end.getTime(); return query(field, beginTime, endTime); }
From source file:com.joe.utilities.core.hibernate.repository.impl.ApplicationConfigurationRepositoryImpl.java
public Long retrieveDBTimeOffsetInMilliseconds() { DbTimestampType type = new DbTimestampType(); Timestamp ts = (Timestamp) type.seed((SessionImplementor) getSession()); Calendar cal = Calendar.getInstance(); long actualTimeDiff = cal.getTimeInMillis() - ts.getTime(); //System.out.println("Actual Time Diff in ms(AS - DB)="+actualTimeDiff); return new Long(actualTimeDiff); }