List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:jp.sonymusicstudio.cast.castcompanionlibrary.utils.Utils.java
/** * Builds and returns a {@link Bundle} which contains a select subset of data in the * {@link MediaInfo}. Since {@link MediaInfo} is not {@link Parcelable}, one can use this * container bundle to pass around from one activity to another. * * @see <code>bundleToMediaInfo()</code> *///w w w .j av a2 s. c o m public static Bundle mediaInfoToBundle(MediaInfo info) { if (info == null) { return null; } MediaMetadata md = info.getMetadata(); Bundle wrapper = new Bundle(); wrapper.putString(MediaMetadata.KEY_TITLE, md.getString(MediaMetadata.KEY_TITLE)); wrapper.putString(MediaMetadata.KEY_SUBTITLE, md.getString(MediaMetadata.KEY_SUBTITLE)); wrapper.putString(MediaMetadata.KEY_ALBUM_TITLE, md.getString(MediaMetadata.KEY_ALBUM_TITLE)); wrapper.putString(MediaMetadata.KEY_ALBUM_ARTIST, md.getString(MediaMetadata.KEY_ALBUM_ARTIST)); wrapper.putString(MediaMetadata.KEY_COMPOSER, md.getString(MediaMetadata.KEY_COMPOSER)); wrapper.putString(MediaMetadata.KEY_SERIES_TITLE, md.getString(MediaMetadata.KEY_SERIES_TITLE)); wrapper.putString(MediaMetadata.KEY_SEASON_NUMBER, md.getString(MediaMetadata.KEY_SEASON_NUMBER)); wrapper.putString(MediaMetadata.KEY_EPISODE_NUMBER, md.getString(MediaMetadata.KEY_EPISODE_NUMBER)); Calendar releaseCalender = md.getDate(MediaMetadata.KEY_RELEASE_DATE); if (releaseCalender != null) { long releaseMillis = releaseCalender.getTimeInMillis(); wrapper.putLong(MediaMetadata.KEY_RELEASE_DATE, releaseMillis); } wrapper.putInt(KEY_MEDIA_TYPE, info.getMetadata().getMediaType()); wrapper.putString(KEY_URL, info.getContentId()); wrapper.putString(MediaMetadata.KEY_STUDIO, md.getString(MediaMetadata.KEY_STUDIO)); wrapper.putString(KEY_CONTENT_TYPE, info.getContentType()); wrapper.putInt(KEY_STREAM_TYPE, info.getStreamType()); wrapper.putLong(KEY_STREAM_DURATION, info.getStreamDuration()); if (!md.getImages().isEmpty()) { ArrayList<String> urls = new ArrayList<>(); for (WebImage img : md.getImages()) { urls.add(img.getUrl().toString()); } wrapper.putStringArrayList(KEY_IMAGES, urls); } JSONObject customData = info.getCustomData(); if (customData != null) { wrapper.putString(KEY_CUSTOM_DATA, customData.toString()); } if (info.getMediaTracks() != null && !info.getMediaTracks().isEmpty()) { try { JSONArray jsonArray = new JSONArray(); for (MediaTrack mt : info.getMediaTracks()) { JSONObject jsonObject = new JSONObject(); jsonObject.put(KEY_TRACK_NAME, mt.getName()); jsonObject.put(KEY_TRACK_CONTENT_ID, mt.getContentId()); jsonObject.put(KEY_TRACK_ID, mt.getId()); jsonObject.put(KEY_TRACK_LANGUAGE, mt.getLanguage()); jsonObject.put(KEY_TRACK_TYPE, mt.getType()); if (mt.getSubtype() != MediaTrack.SUBTYPE_UNKNOWN) { jsonObject.put(KEY_TRACK_SUBTYPE, mt.getSubtype()); } if (mt.getCustomData() != null) { jsonObject.put(KEY_TRACK_CUSTOM_DATA, mt.getCustomData().toString()); } jsonArray.put(jsonObject); } wrapper.putString(KEY_TRACKS_DATA, jsonArray.toString()); } catch (JSONException e) { LOGE(TAG, "mediaInfoToBundle(): Failed to convert Tracks data to json", e); } } return wrapper; }
From source file:dsd.dao.ParametersDAO.java
public static List<Parameter> GetValidParameters(Calendar cal) { try {//w w w . j a v a2 s . c o m Connection con = DAOProvider.getDataSource().getConnection(); ArrayList<Parameter> parametersList = new ArrayList<Parameter>(); try { Object[] parameters = new Object[1]; parameters[0] = new Timestamp(cal.getTimeInMillis()); ResultSet results = DAOProvider.SelectTableSecure( // table part tableNameParameters + " join " + tableNameParameterData + " on " + tableNameParameters + ".ID = " + tableNameParameterData + "." + tableParameterDataFields[0], // select part tableNameParameterData + "." + "ID" + " as " + tableNameParameterData + "_" + "ID" + ", " + tableNameParameterData + "." + tableParameterDataFields[0] + " as " + tableNameParameterData + "_" + tableParameterDataFields[0] + ", " + tableNameParameterData + "." + tableParameterDataFields[1] + " as " + tableNameParameterData + "_" + tableParameterDataFields[1] + ", " + tableNameParameterData + "." + tableParameterDataFields[2] + " as " + tableNameParameterData + "_" + tableParameterDataFields[2] + ", " + tableNameParameterData + "." + tableParameterDataFields[3] + " as " + tableNameParameterData + "_" + tableParameterDataFields[3] + ", " + "parameters.* ", // where part " (parameters_id, timestamp) in (select parameters_id, max(timestamp) " + " from parameter_data " + " where timestamp < ? " + " group by parameters_id " + "); ", // order by part "", con, parameters); while (results.next()) { Parameter parameter = new Parameter(); parameter.setParameterID(results.getLong("ID")); parameter.setAbbreviation(results.getString(tableParametersFields[1])); parameter.setCategory( eParameterCategory.getParameterCategory(results.getInt(tableParametersFields[4]))); parameter.setName(results.getString(tableParametersFields[0])); parameter.setParameterDataID(results.getLong(tableNameParameterData + "_ID")); parameter.setTimestamp(results .getTimestamp(tableNameParameterData + "_" + tableParameterDataFields[3]).getTime()); parameter.setUnit(results.getString(tableParametersFields[2])); parameter.setUserID(results.getInt(tableNameParameterData + "_" + tableParameterDataFields[2])); parameter .setValue(results.getFloat(tableNameParameterData + "_" + tableParameterDataFields[1])); parametersList.add(parameter); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); return parametersList; } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:com.projity.util.DateTime.java
public static long hourFloor(long date) { Calendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(date);//from w ww . j a v a 2s. com cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTimeInMillis(); }
From source file:com.hp.test.framework.Utlis.java
public static String gettimeinMilliSec() throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date now = new Date(); String dateInString = sdf.format(now); Date date = sdf.parse(dateInString); log.info(dateInString);//w w w . j a v a 2 s.c o m log.info("Date - Time in milliseconds : " + date.getTime()); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return String.valueOf(calendar.getTimeInMillis()); }
From source file:Main.java
public static long getEndOfDayMs(int year, int month, int day) { final Calendar date = Calendar.getInstance(); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, month); date.set(Calendar.DAY_OF_MONTH, day); date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND)); return date.getTimeInMillis(); }
From source file:Main.java
public static long getStartOfDayMs(int year, int month, int day) { final Calendar date = Calendar.getInstance(); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, month); date.set(Calendar.DAY_OF_MONTH, day); date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND)); return date.getTimeInMillis(); }
From source file:Main.java
/** * * This method is a utility method to create a new java.sql.Date in one line. * * @param year/* w ww . ja v a 2s .co m*/ * @param month * @param day * @param hour * @param minute * @param second * * @return a populated java.sql.Date with the year, month, hour, minute, and second populated, with no value for millisecond. * */ public static java.sql.Date newDate(Integer year, Integer month, Integer day, Integer hour, Integer minute, Integer second) { // test for null arguments if (year == null) { throw new IllegalArgumentException("Argument 'year' passed in was null."); } if (month == null) { throw new IllegalArgumentException("Argument 'month' passed in was null."); } if (day == null) { throw new IllegalArgumentException("Argument 'day' passed in was null."); } if (hour == null) { throw new IllegalArgumentException("Argument 'hour' passed in was null."); } if (minute == null) { throw new IllegalArgumentException("Argument 'minute' passed in was null."); } if (second == null) { throw new IllegalArgumentException("Argument 'second' passed in was null."); } Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); calendar.clear(Calendar.MILLISECOND); return new java.sql.Date(calendar.getTimeInMillis()); }
From source file:dsd.dao.RawDataDAO.java
public static ArrayList<RawData> GetAllForPeriod(Calendar startDate, Calendar endDate) { try {// w ww. j a v a2 s . co m Connection con = DAOProvider.getDataSource().getConnection(); ArrayList<RawData> rawDataList = new ArrayList<RawData>(); try { Object[] parameters = new Object[2]; parameters[0] = new Timestamp(startDate.getTimeInMillis()); parameters[1] = new Timestamp(endDate.getTimeInMillis()); ResultSet results = DAOProvider.SelectTableSecure(tableName, "*", " timestamp >= ? and timestamp <= ? ", "", con, parameters); while (results.next()) { RawData dataTuple = new RawData(); dataTuple.setRawDataID(results.getInt("ID")); dataTuple.setWindSpeed(results.getFloat(fields[0])); dataTuple.setWindDirection(results.getFloat(fields[1])); dataTuple.setHydrometer(results.getFloat(fields[2])); dataTuple.setSonar(results.getFloat(fields[3])); dataTuple.setSonarType(eSonarType.getSonarType(results.getInt(fields[4]))); dataTuple.setTimestamp(results.getTimestamp(fields[5]).getTime()); rawDataList.add(dataTuple); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); return rawDataList; } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:com.sccl.attech.common.utils.DateUtils.java
/** * ???/*from ww w . jav a 2s .c o m*/ * @param date * @return */ public static long getDateTime(Date date) { long dateTime = 0; String yearStr = DateUtils.getDate("yyyy-MM-dd"); String hourStr = DateUtils.formatDate(date, "HH:mm:ss"); String newStr = yearStr + " " + hourStr; Date parseDate = DateUtils.parseDate(newStr); Calendar cale = Calendar.getInstance(); cale.setTime(parseDate); dateTime = cale.getTimeInMillis(); ; return dateTime; }
From source file:com.projity.util.DateTime.java
public static long dayFloor(long date) { Calendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(date);//from w w w.ja v a 2 s . c o m cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.HOUR_OF_DAY, 0); return cal.getTimeInMillis(); }