List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:Main.java
public static int daysSince(final long date) { final Calendar logDate = Calendar.getInstance(); logDate.setTimeInMillis(date);//from w w w .j a va 2 s.c o m logDate.set(Calendar.SECOND, 0); logDate.set(Calendar.MINUTE, 0); logDate.set(Calendar.HOUR_OF_DAY, 0); final Calendar today = Calendar.getInstance(); today.set(Calendar.SECOND, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.HOUR_OF_DAY, 0); return (int) Math.round((today.getTimeInMillis() - logDate.getTimeInMillis()) / 86400000d); }
From source file:Main.java
public static long getTimesEnd() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.MILLISECOND, 999); return cal.getTimeInMillis(); }
From source file:Main.java
/** * @return Return current day timestamp with YY, MM, dd info ONLY *//*from w ww .j a v a 2 s. c om*/ public static Long getCurrentDayTS() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); }
From source file:Main.java
public static long timeInMillis(int hour, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, 0); long timeBefore = calendar.getTimeInMillis(); if (Calendar.getInstance().getTimeInMillis() > timeBefore) calendar.add(Calendar.DAY_OF_WEEK, 1); return calendar.getTimeInMillis(); }
From source file:Main.java
public static long getTodayStartTime() { Calendar date = new GregorianCalendar(); date.set(Calendar.HOUR_OF_DAY, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 1); return date.getTimeInMillis(); }
From source file:org.pau.assetmanager.viewmodel.chart.ResourceImageGenerator.java
private static void cleanTempFolder(File directory) { Calendar cal = Calendar.getInstance(); int daysBack = 1; cal.add(Calendar.DAY_OF_MONTH, daysBack * -1); long purgeTime = cal.getTimeInMillis(); File[] files = directory.listFiles(); for (File file : files) { if (file.lastModified() < purgeTime) { file.delete();//from w ww.j av a 2s.c o m } } }
From source file:Main.java
/** * calculate day count/*w w w . jav a2s .co m*/ * @param startYear start year * @param startMonth start month * @param startDay start day * @param endYear end year * @param endMonth end month * @param endDay end day * @return day count */ public static int countDays(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay) { Calendar startC = Calendar.getInstance(); startC.set(Calendar.YEAR, startYear); startC.set(Calendar.MONTH, startMonth - 1); startC.set(Calendar.DAY_OF_MONTH, startDay); Calendar endC = Calendar.getInstance(); endC.set(Calendar.YEAR, endYear); endC.set(Calendar.MONTH, endMonth - 1); endC.set(Calendar.DAY_OF_MONTH, endDay); return (int) ((endC.getTimeInMillis() - startC.getTimeInMillis()) / 86400000 + 1); }
From source file:Main.java
/** * Takes a calendar object representing a date/time, ignores its current time zone (which should be the default time zone) * applies that date/time to the sourceTimeZone and returns the relative date/time in the current time zone. * /*www. j a v a 2s .c om*/ * For example, given an input of 13:00 EST and source time zone PST, it will return 16:00 EST * 13:00 EST = 18:00 GMT = 10:00 PST * * @param calendar * @param sourceTimeZone * @return */ public static Calendar convertToTimeZone(Calendar calendar, TimeZone sourceTimeZone) { Calendar result = Calendar.getInstance(); // i.e., 13:00 EST becomes 08:00 GMT long originalTimeInUtc = calendar.getTimeInMillis() + calendar.getTimeZone().getOffset(calendar.getTimeInMillis()); // 08:00 GMT becomes 16:00 PST long sourceTime = originalTimeInUtc - sourceTimeZone.getOffset(originalTimeInUtc); result.setTimeZone(sourceTimeZone); result.setTimeInMillis(sourceTime); /* Log.d(TAG, "Converting "+DEBUG_CALENDAR_OUTPUT.format(new Date(calendar.getTimeInMillis())) +" in ["+sourceTimeZone.getDisplayName()+"] to ["+TimeZone.getDefault().getDisplayName() +"] resulting in "+DEBUG_CALENDAR_OUTPUT_WITH_TIMEZONE.format(new Date(result.getTimeInMillis()))); Log.d(TAG, "Original time in UTC = "+DEBUG_CALENDAR_OUTPUT.format(new Date(originalTimeInUtc))); Log.d(TAG, "Original time in source time zone = "+DEBUG_CALENDAR_OUTPUT.format(new Date(sourceTime))); */ return result; }
From source file:net.sourceforge.fenixedu.util.CalendarUtil.java
public static Integer getNumberOfDaysBetweenDates(Date beginDate, Date endDate) { Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(beginDate);//ww w . j a v a 2s . c om c2.setTime(endDate); long timeBetweenInMillis = c2.getTimeInMillis() - c1.getTimeInMillis(); Integer numberDaysBetweenDates = new Integer(new Long(timeBetweenInMillis / (3600000 * 24)).intValue()); return numberDaysBetweenDates; }
From source file:appmonk.tricks.JsonTricks.java
public static long getIsoTimeInMillis(JSONObject json, String... path) { String timeString = getString(json, path); if (timeString != null) { Calendar cal = TimeTricks.isoStringToCalendar(timeString, null); if (cal != null) { return cal.getTimeInMillis(); }/*from ww w .j av a 2 s.com*/ } return -1; }