List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:com.twitter.elephanttwin.util.DateUtil.java
/** * Convert calendar to mysql timestamp./*w ww . j a v a 2 s. c o m*/ * @param cal the calendar * @return the mysql timestamp */ public static String calendarToMysqlTimestampFormat(Calendar cal) { return MYSQL_TIMESTAMP_FORMATTER.print(cal.getTimeInMillis()); }
From source file:com.twitter.elephanttwin.util.DateUtil.java
/** * Convert calendar to date id timestamp * @param cal the calendar// w w w . jav a 2 s .c o m * @return the output date it */ public static String calendarToDateidTimestampFormat(Calendar cal) { return DATEID_TIMESTAMP_FORMATTER.print(cal.getTimeInMillis()); }
From source file:com.twitter.elephanttwin.util.DateUtil.java
/** * Convert calendar to MMDDHHMM format//w w w . j a va 2 s .c o m * @param cal the calendar * @return output string */ public static String calendarToYyyyMmDdHhMmFormat(Calendar cal) { return YYYY_MM_DD_HH_MM_FORMATTER.print(cal.getTimeInMillis()); }
From source file:com.mozilla.hadoop.hbase.mapreduce.MultiScanTableMapReduceUtil.java
/** * Same as above version but allows for specifying batch size as well * @param startCal//w w w. java 2 s . c o m * @param endCal * @param dateFormat * @param columns * @param caching * @param cacheBlocks * @param batch * @return */ public static Scan[] generateBytePrefixScans(Calendar startCal, Calendar endCal, String dateFormat, List<Pair<String, String>> columns, int caching, boolean cacheBlocks, int batch) { ArrayList<Scan> scans = new ArrayList<Scan>(); SimpleDateFormat rowsdf = new SimpleDateFormat(dateFormat); long endTime = DateUtil.getEndTimeAtResolution(endCal.getTimeInMillis(), Calendar.DATE); byte[] temp = new byte[1]; while (startCal.getTimeInMillis() < endTime) { for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) { int d = Integer.parseInt(rowsdf.format(startCal.getTime())); Scan s = new Scan(); s.setCaching(caching); s.setCacheBlocks(cacheBlocks); if (batch > 1) { s.setBatch(batch); } // add columns for (Pair<String, String> pair : columns) { s.addColumn(pair.getFirst().getBytes(), pair.getSecond().getBytes()); } temp[0] = b; s.setStartRow(Bytes.add(temp, Bytes.toBytes(String.format("%06d", d)))); s.setStopRow(Bytes.add(temp, Bytes.toBytes(String.format("%06d", d + 1)))); if (LOG.isDebugEnabled()) { LOG.info("Adding start-stop range: " + temp + String.format("%06d", d) + " - " + temp + String.format("%06d", d + 1)); } scans.add(s); } startCal.add(Calendar.DATE, 1); } return scans.toArray(new Scan[scans.size()]); }
From source file:Main.java
public static int getStudyDay(Context context) { String startStr = getSP(context, SP_LOGIN).getString(SP_KEY_LOGIN_STUDY_STARTTIME, ""); if (!startStr.equals("")) { long start = Long.parseLong(startStr); long current = Calendar.getInstance().getTimeInMillis(); Calendar s = Calendar.getInstance(); s.setTimeInMillis(start);/*from ww w .j a v a2 s . com*/ s.set(Calendar.HOUR_OF_DAY, 3); s.set(Calendar.MINUTE, 0); s.set(Calendar.SECOND, 0); s.set(Calendar.MILLISECOND, 0); Calendar c = Calendar.getInstance(); c.setTimeInMillis(current); // c.set(Calendar.HOUR_OF_DAY, 12); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); start = s.getTimeInMillis(); current = c.getTimeInMillis(); return (int) ((current - start) / (24 * 60 * 60 * 1000)); } else { return -1; } }
From source file:Main.java
/** * @param startDateTime/*from w w w . java 2 s .c o m*/ * @param endDateTime * @return the difference in hours between the second timestamp and first */ public static double getDifferenceInHours(Timestamp startDateTime, Timestamp endDateTime) { int difference = 0; Calendar startCalendar = Calendar.getInstance(); startCalendar.setTime(startDateTime); Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(endDateTime); // First, get difference in whole days Calendar startCompare = Calendar.getInstance(); startCompare.setTime(startDateTime); startCompare.set(Calendar.HOUR_OF_DAY, 0); startCompare.set(Calendar.MINUTE, 0); Calendar endCompare = Calendar.getInstance(); endCompare.setTime(endDateTime); endCompare.set(Calendar.HOUR_OF_DAY, 0); endCompare.set(Calendar.MINUTE, 0); return (endCalendar.getTimeInMillis() - startCalendar.getTimeInMillis()) / (60.0000 * 60.0000 * 1000.0000); }
From source file:Main.java
/** * Converts an XMLGregorianCalendar to a Date. * * @param xmlDate// w w w .j ava 2 s . c o m * XMLGregorianCalendar to convert. * @return corresponding date object. */ public static Date getDate(final XMLGregorianCalendar xmlDate) { // TODO: is this equivalent to getDate(String) processing above?? // start with UTC, i.e. no daylight savings time. TimeZone timezone = TimeZone.getTimeZone("GMT"); // adjust timezone to match xmldate int offsetMinutes = xmlDate.getTimezone(); if (offsetMinutes != DatatypeConstants.FIELD_UNDEFINED) { timezone.setRawOffset( // convert minutes to milliseconds offsetMinutes * 60 // seconds per minute * 1000 // milliseconds per second ); } // use calendar so parsed date will be UTC Calendar calendar = Calendar.getInstance(timezone); calendar.clear(); calendar.set(xmlDate.getYear(), // xmlcalendar is 1 based, calender is 0 based xmlDate.getMonth() - 1, xmlDate.getDay(), xmlDate.getHour(), xmlDate.getMinute(), xmlDate.getSecond()); Date date = calendar.getTime(); int millis = xmlDate.getMillisecond(); if (millis != DatatypeConstants.FIELD_UNDEFINED) { calendar.setTimeInMillis(calendar.getTimeInMillis() + millis); } return date; }
From source file:fedora.server.security.servletfilters.CacheElement.java
private static final String difference(Calendar earlier, Calendar later) { long milliseconds = later.getTimeInMillis() - earlier.getTimeInMillis(); long days = milliseconds / MILLIS_IN_DAY; milliseconds = milliseconds % MILLIS_IN_DAY; long hours = milliseconds / MILLIS_IN_HOUR; milliseconds = milliseconds % MILLIS_IN_HOUR; long minutes = milliseconds / MILLIS_IN_MINUTE; milliseconds = milliseconds % MILLIS_IN_MINUTE; long seconds = milliseconds / MILLIS_IN_SECOND; milliseconds = milliseconds % MILLIS_IN_SECOND; String rc = format(days, hours, minutes, seconds, milliseconds, null); return rc;//w ww . j av a 2 s . com }
From source file:com.keybox.manage.db.SessionAuditDB.java
/** * deletes audit history for users if after time set in properties file * * @param con DB connection//from w w w .j a va2s. c o m */ public static void deleteAuditHistory(Connection con) { try { //delete logs with no terminal entries PreparedStatement stmt = con.prepareStatement( "delete from session_log where id not in (select session_id from terminal_log)"); stmt.execute(); //take today's date and subtract how many days to keep history Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, (-1 * Integer.parseInt(AppConfig.getProperty("deleteAuditLogAfter")))); //subtract java.sql.Date date = new java.sql.Date(cal.getTimeInMillis()); stmt = con.prepareStatement("delete from session_log where session_tm < ?"); stmt.setDate(1, date); stmt.execute(); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } }
From source file:ezbake.services.provenance.graph.Utils.java
public static ezbake.base.thrift.DateTime convertDate2DateTime(final java.util.Date theDate) { final Calendar cal = new GregorianCalendar(); cal.setTime(theDate);/*from w w w.j a v a 2 s. c o m*/ // get calendar parts final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH) + 1; final int day = cal.get(Calendar.DAY_OF_MONTH); final int hour = cal.get(Calendar.HOUR_OF_DAY); final int minute = cal.get(Calendar.MINUTE); final int second = cal.get(Calendar.SECOND); int offsetMinutes = (cal.getTimeZone().getOffset(cal.getTimeInMillis())) / (1000 * 60); // set thrift DateTime propertiesd final ezbake.base.thrift.DateTime dt = new ezbake.base.thrift.DateTime(); // Date final ezbake.base.thrift.Date date = new ezbake.base.thrift.Date(); date.setMonth((short) month).setDay((short) day).setYear((short) year); dt.setDate(date); // Time with TimeZone final ezbake.base.thrift.Time t = new ezbake.base.thrift.Time(); boolean afterUtc = offsetMinutes > 0; offsetMinutes = Math.abs(offsetMinutes); final ezbake.base.thrift.TimeZone tz = new ezbake.base.thrift.TimeZone((short) (offsetMinutes / 60), (short) (offsetMinutes % 60), afterUtc); t.setHour((short) hour).setMinute((short) minute).setSecond((short) second).setTz(tz); dt.setTime(t); return dt; }