List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:com.redhat.rhn.domain.common.CommonFactory.java
/** * Create a TinyUrl//from w ww. j av a2 s . co m * @param urlIn to tinyfy * @param expires the date we *ADD* 6 hours to to set the expiration on the URL * @return TinyUrl instance */ public static TinyUrl createTinyUrl(String urlIn, Date expires) { String token = RandomStringUtils.randomAlphanumeric(8); TinyUrl existing = lookupTinyUrl(token); while (existing != null) { log.warn("Had collision with: " + token); token = RandomStringUtils.randomAlphanumeric(8); existing = lookupTinyUrl(token); } TinyUrl url = new TinyUrl(); Config c = new Config(); url.setUrl(urlIn); url.setEnabled(true); url.setToken(token); Calendar pcal = Calendar.getInstance(); pcal.setTime(expires); pcal.add(Calendar.HOUR, c.getInt("server.satellite.tiny_url_timeout", 4)); url.setExpires(new Date(pcal.getTimeInMillis())); return url; }
From source file:org.wikipedia.nirvana.nirvanabot.BotReporter.java
public static String printTimeDiff(Calendar time1, Calendar time2) { long start = time1.getTimeInMillis(); long end = time2.getTimeInMillis(); return printTimeDiff(end - start); }
From source file:TimeLib.java
/** * Get the timestamp resulting from clearing (setting to zero) all time * values less than or equal to that of the given field. For example, * clearing to {@link Calendar#HOUR} will floor the time to nearest * hour which occurred before or at the given time (e.g., 1:32 * --> 1:30).// w ww. j a va 2 s. c o m * @param t the reference time * @param c a Calendar instance used to help compute the value, the * state of the Calendar will be overwritten. * @param field the time field to clear to, one of the * {@link java.util.Calendar} fields, or one of the extended fields * provided by this class (MILLENIUM, CENTURY, or DECADE). * @return the cleared time */ public static long getClearedTime(long t, Calendar c, int field) { c.setTimeInMillis(t); TimeLib.clearTo(c, field); return c.getTimeInMillis(); }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Decrements the date by one hour/*from www.ja v a2s.co m*/ * @param date - date to be decremented */ public static void decDateByHour(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.HOUR, -1); date.setTime(cal.getTimeInMillis()); }
From source file:Main.java
public static Date firstTimeOfWeek(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); Date dateBegin = new Date(); dateBegin.setTime(calendar.getTimeInMillis()); return dateBegin; }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Increments the date by one day/*from w ww . ja va 2 s.c om*/ * @param date - date to be incremented */ public static void incDateByDay(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.DAY_OF_MONTH, 1); date.setTime(cal.getTimeInMillis()); }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Decrements the date by one week/*www . ja v a 2s.co m*/ * @param date - date to be decremented * @return decremented date */ public static Date decDateByWeek(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.WEEK_OF_MONTH, -1); date.setTime(cal.getTimeInMillis()); return date; }
From source file:Main.java
public static long getTimeMillisAsHourAndMinute(long millis) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(millis);/*from www . ja va 2s . c o m*/ int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); return calendar.getTimeInMillis(); }
From source file:Main.java
public static Date firstTimeOfMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.DAY_OF_MONTH, 1); Date dateBegin = new Date(); dateBegin.setTime(calendar.getTimeInMillis()); return dateBegin; }
From source file:com.joken.common.utils.ConverterUtils.java
/** * ?/*from ww w. ja v a 2s.c o m*/ * * @param time * :08:30:00 * @param separator * : * @return */ public static Long string2TimeSeconds(String time, String separator) { Calendar cl = Calendar.getInstance(); String[] times = time.split(separator); cl.set(Calendar.HOUR_OF_DAY, Integer.valueOf(times[0])); cl.set(Calendar.MINUTE, Integer.valueOf(times[1])); cl.set(Calendar.SECOND, Integer.valueOf(times[2])); cl.set(Calendar.MILLISECOND, 0); return cl.getTimeInMillis() / 1000; }