List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:com.toptal.conf.SampleDataConfiguration.java
/** * Adds entries to the given user.//from w ww . j a v a2 s. c om * @param user User. */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private void addEntries(final User user) { final ThreadLocalRandom rnd = ThreadLocalRandom.current(); final int size = rnd.nextInt(10, 100); final Calendar cal = Calendar.getInstance(); final long end = cal.getTimeInMillis(); cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 2); final long start = cal.getTimeInMillis(); for (int idx = 0; idx < size; ++idx) { this.entries.save(Entry.builder().date(new Date(rnd.nextLong(start, end))) // @checkstyle MagicNumberCheck (2 lines) .distance(rnd.nextLong(500, 10000)).time(rnd.nextLong(120000, 2400000)).user(user).build()); } }
From source file:com.milos.neo4j.services.impl.ScoreboardServiceImpl.java
@Transactional(readOnly = true) @Override/*from w w w .j a v a 2s . c o m*/ public Iterable<Scoreboard> getDailyScoreboard(Long points) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Long now = calendar.getTimeInMillis(); calendar.add(Calendar.WEEK_OF_MONTH, -1); Iterable<Scoreboard> scoreboards = scoreboardDAO.getFullScoreboard(calendar.getTimeInMillis(), now, points); return scoreboards; }
From source file:free.yhc.feeder.model.Utils.java
/** * * @param since/*from ww w. ja v a 2 s. c om*/ * @param now * @param year * @return * null if error (ex. "since > now", "year < since" or "year > now") * otherwise int[2] is returned. * int[0] : min month (inclusive) [1 ~ 12] * int[1] : max month (inclusive) [1 ~ 12] */ public static int[] getMonths(Calendar since, Calendar now, int year) { int sy = since.get(Calendar.YEAR); int ny = now.get(Calendar.YEAR); if (since.getTimeInMillis() > now.getTimeInMillis() || sy > year || ny < year) return null; // check trivial case at first if (year > sy && year < ny) return new int[] { 1, 12 }; int minm = 1; // min month int maxm = 12; // max month if (year == sy) minm = calendarMonthToMonth(since.get(Calendar.MONTH)); if (year == ny) maxm = calendarMonthToMonth(now.get(Calendar.MONTH)); return new int[] { minm, maxm }; }
From source file:edu.ku.brc.specify.conversion.ConvertMiscData.java
/** * /*from w ww . j av a 2s .c o m*/ */ public static void convertObservations(final Connection oldDBConn, final Connection newDBConn, final int disciplineID) { IdMapperMgr.getInstance().setDBs(oldDBConn, newDBConn); String sql = "SELECT cc.CollectionObjectCatalogID, o.ObservationID, o.Text1, o.Text2, o.Number1, o.Remarks "; String baseSQL = " FROM collectionobjectcatalog AS cc Inner Join observation AS o ON cc.CollectionObjectCatalogID = o.BiologicalObjectID"; String ORDERBY = " ORDER BY cc.CollectionObjectCatalogID"; Calendar cal = Calendar.getInstance(); Timestamp tsCreated = new Timestamp(cal.getTimeInMillis()); IdMapperIFace coMapper = IdMapperMgr.getInstance().get("collectionobjectcatalog", "CollectionObjectCatalogID"); if (coMapper == null) { coMapper = IdMapperMgr.getInstance().addTableMapper("collectionobjectcatalog", "CollectionObjectCatalogID", false); } int totalCnt = BasicSQLUtils.getCountAsInt(oldDBConn, "SELECT COUNT(*) " + baseSQL); if (totalCnt < 1) return; Statement stmt = null; PreparedStatement pStmt = null; PreparedStatement updateStmt = null; PreparedStatement insertStmt = null; PreparedStatement updateCOStmt = null; try { pStmt = newDBConn.prepareStatement( "SELECT co.CollectionObjectAttributeID FROM collectionobject AS co WHERE co.CollectionObjectID = ? AND co.CollectionObjectAttributeID IS NOT NULL"); updateStmt = newDBConn.prepareStatement( "UPDATE collectionobjectattribute SET Text1=?, Text2=?, Number1=?, Remarks=? WHERE CollectionObjectAttributeID = ?"); insertStmt = newDBConn.prepareStatement( "INSERT INTO collectionobjectattribute (Version, TimestampCreated, CollectionMemberID, CreatedByAgentID, Text1, Text2, Number1, Remarks) VALUES(0, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); updateCOStmt = newDBConn.prepareStatement( "UPDATE collectionobject SET CollectionObjectAttributeID=? WHERE CollectionObjectID = ?"); int cnt = 0; stmt = oldDBConn.createStatement(); ResultSet rs = stmt.executeQuery(sql + baseSQL + ORDERBY); while (rs.next()) { int ccId = rs.getInt(1); String text1 = rs.getString(3); String text2 = rs.getString(4); Integer number1 = rs.getInt(5); String remarks = rs.getString(6); Integer newId = coMapper.get(ccId); if (newId == null) { log.error("Old Co Id [" + ccId + "] didn't map to new ID."); continue; } pStmt.setInt(1, newId); ResultSet rs2 = pStmt.executeQuery(); if (rs2.next()) { updateStmt.setString(1, text1); updateStmt.setString(2, text2); updateStmt.setInt(3, number1); updateStmt.setString(4, remarks); updateStmt.setInt(5, rs2.getInt(1)); if (updateStmt.executeUpdate() != 1) { log.error("Error updating collectionobjectattribute"); } } else { int memId = BasicSQLUtils.getCountAsInt( "SELECT CollectionMemberID FROM collectionobject WHERE CollectionObjectID = " + newId); insertStmt.setTimestamp(1, tsCreated); insertStmt.setInt(2, memId); insertStmt.setInt(3, 1); // Created By Agent insertStmt.setString(4, text1); insertStmt.setString(5, text2); insertStmt.setInt(6, number1); insertStmt.setString(7, remarks); if (insertStmt.executeUpdate() != 1) { log.error("Error inserting collectionobjectattribute"); } int newCOAId = BasicSQLUtils.getInsertedId(insertStmt); updateCOStmt.setInt(1, newCOAId); updateCOStmt.setInt(2, newId); if (updateCOStmt.executeUpdate() != 1) { log.error( "Error updating collectionobject newCOAId[" + newCOAId + "] newId[" + newId + "]"); } } rs2.close(); cnt++; if (cnt % 1000 == 0) { System.out.println(String.format("%d / %d", cnt, totalCnt)); } } rs.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (stmt != null) stmt.close(); if (pStmt != null) pStmt.close(); if (updateStmt != null) updateStmt.close(); if (insertStmt != null) insertStmt.close(); if (updateCOStmt != null) updateCOStmt.close(); } catch (SQLException ex) { } } }
From source file:md.ibanc.rm.spring.service.SingInOutSessionsServiceImpl.java
@Override @Transactional//from ww w . j av a 2 s .co m public SingInOutSessions save(String guidId, Customers customers, HttpServletRequest request) { Sessions sessions = new Sessions(); Calendar cal = Calendar.getInstance(); Timestamp timestamp = new Timestamp(cal.getTimeInMillis()); sessions.setCreatedAt(timestamp); sessions.setSessionUid(guidId); sessionsDAO.save(sessions); SingInOutSessions singInOutSessions = new SingInOutSessions(); singInOutSessions.setCustomers(customers); singInOutSessions.setSessions(sessions); singInOutSessions.setSingInDate(timestamp); singInOutSessions.setIp(request.getRemoteAddr()); singInOutSessions.setLocation(request.getRemoteUser()); singInOutSessionsDAO.save(singInOutSessions); return singInOutSessions; }
From source file:ru.anr.base.BaseParent.java
/** * @param pattern//from w w w . ja v a 2 s . c o m * patter * @param date * date * @return formatted date */ public static String formatDate(String pattern, Calendar date) { return DateTimeFormatter.ofPattern(pattern).format( LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTimeInMillis()), ZoneId.systemDefault())); }
From source file:com.sonyericsson.jenkins.plugins.bfa.graphs.TimeSeriesUnkownFailuresChart.java
@Override protected JFreeChart createGraph() { TimeTableXYDataset dataset = createDataset(); ValueAxis xAxis = new DateAxis(); xAxis.setLowerMargin(0.0);/*from ww w . ja v a2s. co m*/ xAxis.setUpperMargin(0.0); Calendar lowerBound = getLowerGraphBound(); xAxis.setRange(lowerBound.getTimeInMillis(), Calendar.getInstance().getTimeInMillis()); NumberAxis yAxis = new NumberAxis(Y_AXIS_LABEL); yAxis.setRange(0, HUNDRED_PERCENT); XYItemRenderer renderer = new XYBarRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(graphTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.removeLegend(); return chart; }
From source file:it.geosolutions.opensdi2.session.impl.UserSessionImpl.java
@Override public void refresh() { if (expiration != null) { Calendar newExpiration = Calendar.getInstance(); newExpiration.setTimeInMillis(newExpiration.getTimeInMillis() + expirationInterval); setExpiration(newExpiration);//from w w w .j a va 2 s. c o m } }
From source file:Process.java
public double calcularNivelRiesgo() { Calendar inicio = Calendar.getInstance(); double diferencia = 0; do {/*from www . jav a2s.com*/ Calendar ahora = Calendar.getInstance(); diferencia = (int) ((ahora.getTimeInMillis() - inicio.getTimeInMillis()) / 1000); //System.out.println(diferencia); } while (diferencia < 25); return 1 + (int) (Math.random() * 10); }
From source file:adalid.commons.util.TimeUtils.java
public static Time addTime(java.util.Date date, int addend, char unit) { if (date == null) { return null; }// w w w . j a va 2 s . c o m Calendar c = newTimeCalendar(date); if (addend != 0) { switch (unit) { case 'h': c.add(Calendar.HOUR, addend); break; case 'm': c.add(Calendar.MINUTE, addend); break; case 's': c.add(Calendar.SECOND, addend); break; default: break; } } return new Time(c.getTimeInMillis()); }