List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:com.infinities.nova.snapshots.api.DaseinSnapshotsApi.java
/** * @param snapshot//from w ww . j av a2s . co m * @return */ private Snapshot toSnapshot(org.dasein.cloud.compute.Snapshot snapshot) { Snapshot ret = new Snapshot(); Calendar createdAt = Calendar.getInstance(); createdAt.setTimeInMillis(snapshot.getSnapshotTimestamp()); ret.setCreatedAt(createdAt); ret.setDescription(snapshot.getDescription()); ret.setId(snapshot.getProviderSnapshotId()); ret.setName(snapshot.getName()); ret.setSize(snapshot.getSizeInGb()); ret.setStatus(snapshot.getCurrentState().name()); ret.setVolumeId(snapshot.getVolumeId()); return ret; }
From source file:com.wildplot.android.ankistats.CollectionData.java
private void _updateCutoff() { // calculate days since col created and store in mToday mToday = 0;/*from www. ja v a 2 s .c o m*/ Calendar crt = GregorianCalendar.getInstance(); crt.setTimeInMillis(mCrt * 1000); // creation time (from crt as stored in database) Calendar fromNow = GregorianCalendar.getInstance(); // decremented towards crt // code to avoid counting years worth of days int yearSpan = fromNow.get(Calendar.YEAR) - crt.get(Calendar.YEAR); if (yearSpan > 1) { // at least one full year has definitely lapsed since creation int toJump = 365 * (yearSpan - 1); fromNow.add(Calendar.YEAR, -toJump); if (fromNow.compareTo(crt) < 0) { // went too far, reset and do full count fromNow = GregorianCalendar.getInstance(); } else { mToday += toJump; } } // count days backwards while (fromNow.compareTo(crt) > 0) { fromNow.add(Calendar.DAY_OF_MONTH, -1); if (fromNow.compareTo(crt) >= 0) { mToday++; } } crt.add(Calendar.DAY_OF_YEAR, mToday + 1); mDayCutoff = crt.getTimeInMillis() / 1000; }
From source file:de.codecentric.jira.jenkins.plugin.util.TimeDifferenceHelper.java
private int countYears(long startMillis, long endMillis) { Calendar start = Calendar.getInstance(); start.setTimeInMillis(startMillis); Calendar end = Calendar.getInstance(); end.setTimeInMillis(endMillis);/*from ww w. j av a2s .c om*/ int years; if (start.get(Calendar.MONTH) > end.get(Calendar.MONTH)) { years = end.get(Calendar.YEAR) - start.get(Calendar.YEAR) - 1; } else { years = end.get(Calendar.YEAR) - start.get(Calendar.YEAR); } return years; }
From source file:de.codecentric.jira.jenkins.plugin.util.TimeDifferenceHelper.java
private int countMonths(long startMillis, long endMillis) { Calendar start = Calendar.getInstance(); start.setTimeInMillis(startMillis); Calendar end = Calendar.getInstance(); end.setTimeInMillis(endMillis);/*from w w w . j a va 2 s . com*/ int month; if (start.get(Calendar.DAY_OF_MONTH) > end.get(Calendar.DAY_OF_MONTH)) { month = end.get(Calendar.MONTH) - start.get(Calendar.MONTH) - 1; } else { month = end.get(Calendar.MONTH) - start.get(Calendar.MONTH); } if (month < 0) { return month + 12; } else { return month; } }
From source file:net.sf.l2j.gameserver.model.entity.ClanHallSiege.java
public void setNewSiegeDate(long siegeDate, int ClanHallId, int hour) { Calendar tmpDate = Calendar.getInstance(); if (siegeDate <= System.currentTimeMillis()) { tmpDate.setTimeInMillis(System.currentTimeMillis()); tmpDate.add(Calendar.DAY_OF_MONTH, 3); tmpDate.set(Calendar.DAY_OF_WEEK, 6); tmpDate.set(Calendar.HOUR_OF_DAY, hour); tmpDate.set(Calendar.MINUTE, 0); tmpDate.set(Calendar.SECOND, 0); setSiegeDate(tmpDate);/* w ww . j a v a 2 s.c om*/ Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con .prepareStatement("UPDATE clanhall_siege SET siege_data=? WHERE id = ?"); statement.setLong(1, getSiegeDate().getTimeInMillis()); statement.setInt(2, ClanHallId); statement.execute(); statement.close(); } catch (Exception e) { _log.error("Exception: can't save clanhall siege date: " + e.getMessage(), e); } finally { try { if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:com.ichi2.libanki.Utils.java
public static void printDate(String name, double date) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); df.setTimeZone(TimeZone.getTimeZone("GMT")); Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis((long) date * 1000); Timber.d("Value of %s: %s", name, cal.getTime().toGMTString()); }
From source file:cat.albirar.framework.dynabean.impl.DynaBeanDateEditor.java
@Override public void setAsText(String text) throws IllegalArgumentException { Date d;/*from w ww.j av a2s. c o m*/ Calendar cal; try { d = formatter.parse(text); if (typeCalendar) { cal = Calendar.getInstance(); cal.setTimeInMillis(d.getTime()); setValue(cal); } else { setValue(d); } } catch (ParseException e) { logger.error("When parsing text '" + text + "' to Date type", e); setValue(null); } }
From source file:com.ichi2.libanki.Utils.java
/** * Returns the effective date of the present moment. * If the time is prior the cut-off time (9:00am by default as of 11/02/10) return yesterday, * otherwise today/*from ww w . j ava2 s .c om*/ * Note that the Date class is java.sql.Date whose constructor sets hours, minutes etc to zero * * @param utcOffset The UTC offset in seconds we are going to use to determine today or yesterday. * @return The date (with time set to 00:00:00) that corresponds to today in Anki terms */ public static Date genToday(double utcOffset) { // The result is not adjusted for timezone anymore, following libanki model // Timezone adjustment happens explicitly in Deck.updateCutoff(), but not in Deck.checkDailyStats() SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); df.setTimeZone(TimeZone.getTimeZone("GMT")); Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(System.currentTimeMillis() - (long) utcOffset * 1000l); return Date.valueOf(df.format(cal.getTime())); }
From source file:gov.nih.nci.caxchange.messaging.AdverseEventLoadTest.java
/** * Testcase for sending the messages//from w ww . j av a2s. c o m * * @throws InterruptedException - InterruptedException */ @Test public void sendAdverseEventMessage() throws InterruptedException { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currDt.getTime() + 5000); currDt = calendar.getTime(); final Timer timer = new Timer(); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); timer.schedule(getTimerTask(), currDt); es.awaitTermination(3, TimeUnit.MINUTES); }
From source file:gov.nih.nci.caxchange.messaging.RegistrationLoadTest.java
/** * Testcase for sending the messages/*from w w w.j av a 2s .c om*/ * * @throws InterruptedException - InterruptedException */ @Test public void sendRegistrationMessage() throws InterruptedException { final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(currDt.getTime() + 5000); currDt = calendar.getTime(); final Timer timer = new Timer(); timer.schedule(getTimerTask(0), currDt); timer.schedule(getTimerTask(1), currDt); timer.schedule(getTimerTask(2), currDt); timer.schedule(getTimerTask(3), currDt); timer.schedule(getTimerTask(4), currDt); timer.schedule(getTimerTask(5), currDt); timer.schedule(getTimerTask(6), currDt); timer.schedule(getTimerTask(7), currDt); timer.schedule(getTimerTask(8), currDt); timer.schedule(getTimerTask(9), currDt); timer.schedule(getTimerTask(10), currDt); timer.schedule(getTimerTask(11), currDt); timer.schedule(getTimerTask(12), currDt); timer.schedule(getTimerTask(13), currDt); timer.schedule(getTimerTask(14), currDt); timer.schedule(getTimerTask(15), currDt); timer.schedule(getTimerTask(16), currDt); timer.schedule(getTimerTask(17), currDt); timer.schedule(getTimerTask(18), currDt); timer.schedule(getTimerTask(19), currDt); es.awaitTermination(3, TimeUnit.MINUTES); }