List of usage examples for java.util Calendar getTimeInMillis
public long getTimeInMillis()
From source file:Dates.java
/** * Given a date, a proper TimeZone, return the ending date of the month of the * specified date and TimeZone. If TimeZone is null, meaning use default * TimeZone of the JVM./*from ww w . j ava2s . c o m*/ */ final public static Date endOfMonth(Date when, TimeZone tz) { if (tz == null) tz = TimeZones.getCurrent(); final Calendar cal = Calendar.getInstance(tz); cal.setTimeInMillis(when.getTime()); // don't call cal.setTime(Date) which // will reset the TimeZone. final int year = cal.get(Calendar.YEAR); final int month = cal.get(Calendar.MONTH); final int monthDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.clear(); cal.set(year, month, monthDays + 1); cal.setTimeInMillis(cal.getTimeInMillis() - 1); return cal.getTime(); }
From source file:by.creepid.docsreporter.AbstractDocsReporterIT.java
protected String getTimestamp() { Calendar cal = Calendar.getInstance(); return String.valueOf(cal.getTimeInMillis()); }
From source file:com.linkedin.databus2.producers.gg.GGEventGenerationFactory.java
public static long ggTimeStampStringToMilliSeconds(String value) throws DatabusException { Pattern _pattern = Pattern.compile("(\\d{4})-(\\d{2})-(\\d{2}):(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d{0,9})"); Matcher matcher = _pattern.matcher(value); if (!matcher.matches() || matcher.groupCount() != 7) { throw new DatabusException("The timestamp format is not as expected, cannot proceed!"); }/* ww w .j a va 2 s. c o m*/ Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); //Explicitly set ms to zero; without initialization it has random ms values :( calendar.set(Calendar.MILLISECOND, 0); calendar.set(Integer.valueOf(matcher.group(1)), Integer.valueOf(matcher.group(2)) - 1, Integer.valueOf(matcher.group(3)), Integer.valueOf(matcher.group(4)), Integer.valueOf(matcher.group(5)), Integer.valueOf(matcher.group(6))); //Prune to the first 3 digits or less String milliSecondsString = matcher.group(7); int maxSecondsLength = (milliSecondsString.length() > 3) ? 3 : milliSecondsString.length(); String prunedMilliSeconds = milliSecondsString.substring(0, maxSecondsLength); //Add the ms value to the calendar object calendar.add(Calendar.MILLISECOND, Integer.valueOf(prunedMilliSeconds)); return calendar.getTimeInMillis(); }
From source file:com.neuron.trafikanten.HelperFunctions.java
public static Long jsonToDate(String jsonString) { Calendar calendar = Calendar.getInstance(); int indexOfPlus = jsonString.indexOf("+"); int startOfDate = 5; if (jsonString.startsWith("/")) { // LEGACY : parse /Date( strings : Some date strings are /Date(253402297140000+0100)/, new ones are Date(253402297140000+0100) startOfDate = 6;/* w w w . j av a2 s .c o m*/ calendar.setTimeInMillis(Long.parseLong( jsonString.substring(startOfDate, indexOfPlus > 0 ? indexOfPlus : jsonString.length() - 2))); } else { calendar.setTimeInMillis(Long.parseLong( jsonString.substring(startOfDate, indexOfPlus > 0 ? indexOfPlus : jsonString.length() - 1))); } if (indexOfPlus > -1) { calendar.setTimeZone( TimeZone.getTimeZone("GMT-" + jsonString.substring(indexOfPlus, indexOfPlus + 3) + ":00")); } return calendar.getTimeInMillis(); }
From source file:adalid.commons.util.TimeUtils.java
private static Timestamp merge(java.util.Date date, java.util.Date time) { Calendar d = Calendar.getInstance(); Calendar t = Calendar.getInstance(); d.setTimeInMillis(date.getTime());//from w w w . j a v a 2 s. c o m t.setTimeInMillis(time.getTime()); d.set(Calendar.HOUR_OF_DAY, t.get(Calendar.HOUR_OF_DAY)); d.set(Calendar.MINUTE, t.get(Calendar.MINUTE)); d.set(Calendar.SECOND, t.get(Calendar.SECOND)); d.set(Calendar.MILLISECOND, t.get(Calendar.MILLISECOND)); return new Timestamp(d.getTimeInMillis()); }
From source file:net.chrisrichardson.foodToGo.restaurantNotificationService.tsImpl.dao.OrderDAOIBatisImpl.java
Timestamp calculateCutOffTime() { Calendar c = Calendar.getInstance(); c.add(Calendar.MINUTE, -timeWindowInMinutes); long cutOffTime = c.getTimeInMillis(); return new Timestamp(cutOffTime); }
From source file:com.px100systems.util.SpringELCtx.java
/** * Returns adjusted midnight time// ww w .j ava2s. co m * @param date time to adjust * @param dayOffset add or subtract days * @return the adjusted time */ public static long adjustedMidnight(Date date, Integer dayOffset) { Calendar cal = Calendar.getInstance(); cal.setTime(date); 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() + (millisecondsInDay * dayOffset); }
From source file:com.milos.neo4j.services.impl.ScoreboardServiceImpl.java
@Transactional(readOnly = true) @Override/*from w w w. j a v a 2s .com*/ public Iterable<Scoreboard> getMontlyScoreboard(Long points) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Long now = calendar.getTimeInMillis(); calendar.add(Calendar.MONTH, -1); return scoreboardDAO.getFullScoreboard(calendar.getTimeInMillis(), now, points); }
From source file:com.milos.neo4j.services.impl.ScoreboardServiceImpl.java
@Transactional(readOnly = true) @Override/*from w ww. ja v a 2 s.c o m*/ public Iterable<Scoreboard> getWeeklyScoreboard(Long points) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Long now = calendar.getTimeInMillis(); calendar.add(Calendar.WEEK_OF_MONTH, -1); return scoreboardDAO.getFullScoreboard(calendar.getTimeInMillis(), now, points); }
From source file:com.milos.neo4j.services.impl.ScoreboardServiceImpl.java
@Transactional(readOnly = true) @Override/*from w w w . j a va 2 s .c o m*/ public List<Scoreboard> getWinningsScoreboard(Long points) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Long now = calendar.getTimeInMillis(); calendar.add(Calendar.MONTH, -1); return scoreboardDAO.getWinningsScoreboard(calendar.getTimeInMillis(), now, points); }