List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:Main.java
public static long getDiffOfMillis(Date starDate, Date endDate) { Calendar star = Calendar.getInstance(); star.setTime(starDate);/* ww w . j a va2 s . c o m*/ Calendar end = Calendar.getInstance(); end.setTime(endDate); long diff = star.getTimeInMillis() - end.getTimeInMillis(); long diffMillis = (Math.abs(diff)); return diffMillis; }
From source file:com.github.jgility.core.util.ReleasePlanningUtils.java
private static long calculateRangeInDays(Calendar start, Calendar end) { long diff = end.getTimeInMillis() - start.getTimeInMillis(); return diff / (1000 * 60 * 60 * 24); }
From source file:Main.java
private static long beginningOfTheDay(Calendar time) { Calendar copy = (Calendar) time.clone(); copy.clear();/*from ww w . ja v a2 s .com*/ copy.set(time.get(Calendar.YEAR), time.get(Calendar.MONTH), time.get(Calendar.DAY_OF_MONTH)); return copy.getTimeInMillis(); }
From source file:com.espertech.esper.epl.datetime.calop.CalendarOpPlusFastAddHelper.java
public static CalendarOpPlusFastAddResult computeNextDue(long currentTime, TimePeriod timePeriod, Calendar reference) { if (reference.getTimeInMillis() > currentTime) { return new CalendarOpPlusFastAddResult(0, reference); }// w ww.j a v a2 s . c o m // add one time period Calendar work = (Calendar) reference.clone(); if (DEBUG && log.isDebugEnabled()) { log.debug("Work date is " + DateTime.print(work)); } CalendarOpPlusMinus.actionSafeOverflow(work, 1, timePeriod); long inMillis = work.getTimeInMillis(); if (inMillis > currentTime) { return new CalendarOpPlusFastAddResult(1, work); } if (DEBUG && log.isDebugEnabled()) { log.debug("Work date is " + DateTime.print(work)); } long factor = 1; // determine multiplier long deltaCurrentToStart = currentTime - reference.getTimeInMillis(); long deltaAddedOne = work.getTimeInMillis() - reference.getTimeInMillis(); double multiplierDbl = (deltaCurrentToStart / deltaAddedOne) - 1; long multiplierRoundedLong = (long) multiplierDbl; // handle integer max while (multiplierRoundedLong > Integer.MAX_VALUE) { CalendarOpPlusMinus.actionSafeOverflow(work, Integer.MAX_VALUE, timePeriod); factor += Integer.MAX_VALUE; multiplierRoundedLong -= Integer.MAX_VALUE; if (DEBUG && log.isDebugEnabled()) { log.debug("Work date is " + DateTime.print(work) + " factor " + factor); } } // add int multiplierRoundedInt = (int) multiplierRoundedLong; CalendarOpPlusMinus.actionSafeOverflow(work, multiplierRoundedInt, timePeriod); factor += multiplierRoundedInt; // if below, add more if (work.getTimeInMillis() <= currentTime) { while (work.getTimeInMillis() <= currentTime) { CalendarOpPlusMinus.actionSafeOverflow(work, 1, timePeriod); factor += 1; if (DEBUG && log.isDebugEnabled()) { log.debug("Work date is " + DateTime.print(work) + " factor " + factor); } } return new CalendarOpPlusFastAddResult(factor, work); } // we are over while (work.getTimeInMillis() > currentTime) { CalendarOpPlusMinus.actionSafeOverflow(work, -1, timePeriod); factor -= 1; if (DEBUG && log.isDebugEnabled()) { log.debug("Work date is " + DateTime.print(work) + " factor " + factor); } } CalendarOpPlusMinus.actionSafeOverflow(work, 1, timePeriod); if (DEBUG && log.isDebugEnabled()) { log.debug("Work date is " + DateTime.print(work) + " factor " + factor); } return new CalendarOpPlusFastAddResult(factor + 1, work); }
From source file:com.alibaba.ims.platform.util.DateUtil.java
/** * ?UTC/*from w w w . j ava 2 s . c o m*/ * * @return */ public static long getUTCTimeInMillis() { Calendar cal = Calendar.getInstance(); return cal.getTimeInMillis() - cal.get(Calendar.ZONE_OFFSET); }
From source file:Main.java
public static long getTodayZeroTimeInMillis() { Calendar calendar = getZeroSecondCalendar(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); return calendar.getTimeInMillis(); }
From source file:Main.java
private static TimeZone guessTimeZone(Calendar c, String country) { return TimeUtils.getTimeZone(c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET), c.get(Calendar.DST_OFFSET) != 0, c.getTimeInMillis(), country); }
From source file:ezbake.services.provenance.graph.Utils.java
public static Long convertDateTime2Millis(final DateTime dateTime) { Calendar calendar = DateTimeConverter.transformDateTime(dateTime); return calendar.getTimeInMillis(); }
From source file:Main.java
public static long CompareTimeDelta(String arrivalTime) { Calendar calendarToday = Calendar.getInstance(); Calendar calendarTrainArrival = Calendar.getInstance(); long millisecondsCurrent = calendarToday.getTimeInMillis(); long millisecondsTrainArrival; int nowYear = calendarToday.get(Calendar.YEAR); int nowMonth = calendarToday.get(Calendar.MONTH); int nowDay = calendarToday.get(Calendar.DATE); int evalhr = 0; int evalmin = 0; int evalsec = 0; String delims = "[:]"; String[] timesplit = arrivalTime.split(delims); evalhr = Integer.parseInt(timesplit[0]); //HR evalmin = Integer.parseInt(timesplit[1]); //MIN evalsec = Integer.parseInt(timesplit[2]); //SEC - VRE does not provide a schedule down to seconds, so ignore. calendarTrainArrival.set(nowYear, nowMonth, nowDay, evalhr, evalmin); millisecondsTrainArrival = calendarTrainArrival.getTimeInMillis(); return millisecondsCurrent - millisecondsTrainArrival; }
From source file:gov.nih.nci.caintegrator.application.analysis.SurvivalCalculator.java
private static int daysBetween(Calendar startDate, Calendar endDate) { return Math.round( ((endDate.getTimeInMillis() - startDate.getTimeInMillis() + ONE_HOUR)) / (ONE_HOUR * HOURS_IN_DAY)); }