List of usage examples for java.util Date getTime
public long getTime()
From source file:edu.cornell.mannlib.semservices.util.DateConverter.java
public static String toFormattedString(Date date) { String s = new String(); s = new SimpleDateFormat("MMM d, h:mm a").format(date.getTime()); return s;/* w ww.j av a 2s . c om*/ }
From source file:dhbw.clippinggorilla.external.twitter.TwitterUtils.java
private static Article fillArticle(Status status) { Article article = new Article(); article.setTitle(status.getUser().getName()); article.setDescription(status.getText()); article.setBody(status.getText());//w ww . j a va 2 s .co m article.setSource(SourceUtils.TWITTER); for (MediaEntity mediaEntity : status.getMediaEntities()) { if (!mediaEntity.getType().equals("video")) { article.setUrlToImage(mediaEntity.getMediaURL()); break; } } if (article.getUrlToImage().isEmpty()) { article.setUrlToImage(status.getUser().getBiggerProfileImageURL()); } article.setUrl("https://twitter.com/" + status.getUser().getScreenName() + "/status/" + status.getId()); article.setId(status.getId() + ""); article.setAuthor("@" + status.getUser().getScreenName()); Date date = status.getCreatedAt(); Instant instant = Instant.ofEpochMilli(date.getTime()); LocalDateTime createdAt = LocalDateTime.ofInstant(instant, ZoneOffset.UTC); article.setPublishedAt(createdAt.toString()); return article; }
From source file:Main.java
public static String getCurrentAgeByBirthdate(String brithday) { SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date date = new Date(); java.util.Date mydate = null; try {/* w w w . j av a 2s. c o m*/ mydate = myFormatter.parse(brithday); } catch (ParseException e) { e.printStackTrace(); } long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000) + 1; String year = new java.text.DecimalFormat("#").format(day / 365f); return year; }
From source file:it.inserpio.mapillary.gopro.importer.parser.bikematepro.transformer.BikeMateProGPXTransformer.java
public static List<GPXDateTimePoint> translate(BikeMateProGPX bikeMateProGPX) throws ParseException { List<GPXDateTimePoint> result = null; Assert.notNull(bikeMateProGPX);/*from ww w. j a va 2s . c om*/ Assert.notNull(bikeMateProGPX.getTrk()); if (CollectionUtils.isNotEmpty(bikeMateProGPX.getTrk().getTrksegs())) { for (BikeMateProTRKSEG bikeMateProTRKSEG : bikeMateProGPX.getTrk().getTrksegs()) { result = new ArrayList<GPXDateTimePoint>(); for (BikeMateProTRKPT bikeMateProTRKPT : bikeMateProTRKSEG.getTrkpts()) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); Date date = dateFormat.parse(bikeMateProTRKPT.getTime()); result.add(new GPXDateTimePoint(bikeMateProTRKPT.getLon(), bikeMateProTRKPT.getLat(), date.getTime())); } } } return result; }
From source file:io.apicurio.studio.fe.servlet.servlets.DownloadServlet.java
/** * Disable caching./*from w w w .ja v a 2s . c om*/ * @param httpResponse */ private static void disableHttpCaching(HttpServletResponse httpResponse) { Date now = new Date(); httpResponse.setDateHeader("Date", now.getTime()); //$NON-NLS-1$ httpResponse.setDateHeader("Expires", expiredSinceYesterday(now)); //$NON-NLS-1$ httpResponse.setHeader("Pragma", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$ httpResponse.setHeader("Cache-control", "no-cache, no-store, must-revalidate"); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:Urls.java
/** * Returns the time when the document should be considered expired. * The time will be zero if the document always needs to be revalidated. * It will be <code>null</code> if no expiration time is specified. *//* ww w.j a v a 2 s . c o m*/ public static Long getExpiration(URLConnection connection, long baseTime) { String cacheControl = connection.getHeaderField("Cache-Control"); if (cacheControl != null) { StringTokenizer tok = new StringTokenizer(cacheControl, ","); while (tok.hasMoreTokens()) { String token = tok.nextToken().trim().toLowerCase(); if ("must-revalidate".equals(token)) { return new Long(0); } else if (token.startsWith("max-age")) { int eqIdx = token.indexOf('='); if (eqIdx != -1) { String value = token.substring(eqIdx + 1).trim(); int seconds; try { seconds = Integer.parseInt(value); return new Long(baseTime + seconds * 1000); } catch (NumberFormatException nfe) { logger.warning("getExpiration(): Bad Cache-Control max-age value: " + value); // ignore } } } } } String expires = connection.getHeaderField("Expires"); if (expires != null) { try { synchronized (PATTERN_RFC1123) { Date expDate = PATTERN_RFC1123.parse(expires); return new Long(expDate.getTime()); } } catch (java.text.ParseException pe) { int seconds; try { seconds = Integer.parseInt(expires); return new Long(baseTime + seconds * 1000); } catch (NumberFormatException nfe) { logger.warning("getExpiration(): Bad Expires header value: " + expires); } } } return null; }
From source file:com.epam.ta.reportportal.commons.Preconditions.java
/** * Start time of item to be creates is later than provided start time * //from w w w . j a v a2 s .c om * @param startTime * @return */ public static Predicate<StartTestItemRQ> startSameTimeOrLater(final Date startTime) { return input -> input.getStartTime() != null && input.getStartTime().getTime() >= startTime.getTime(); }
From source file:com.splunk.shuttl.testutil.TUtilsBucket.java
private static String getNameWithEarliestAndLatestTime(Date earliest, Date latest) { return "db_" + toSec(latest.getTime()) + "_" + toSec(earliest.getTime()) + "_" + randomIndexName(); }
From source file:com.alibaba.ims.platform.util.DateUtil.java
/** * /*from w w w. j a v a2 s . c o m*/ * * @param date1 * @param date2 * @return */ public static long minus(Date date1, Date date2) { if (date1 == null || date2 == null) { return Long.MAX_VALUE; } return ((date1.getTime() - date2.getTime() - 1) / DateUtils.MILLIS_PER_DAY) + 1; }
From source file:be.fedict.eid.applet.service.impl.AuthenticationChallenge.java
/** * Gives back the authentication challenge. This challenge is checked for * freshness and can be consumed only once. * /* w ww. j a v a2 s . co m*/ * @param session * @param maxMaturity * @return */ public static byte[] getAuthnChallenge(HttpSession session, Long maxMaturity) { AuthenticationChallenge authenticationChallenge = (AuthenticationChallenge) session .getAttribute(AUTHN_CHALLENGE_SESSION_ATTRIBUTE); if (null == authenticationChallenge) { throw new SecurityException("no challenge in session"); } session.removeAttribute(AUTHN_CHALLENGE_SESSION_ATTRIBUTE); Date now = new Date(); if (null == maxMaturity) { maxMaturity = DEFAULT_MAX_MATURITY; } long dt = now.getTime() - authenticationChallenge.getTimestamp().getTime(); if (dt > maxMaturity) { throw new SecurityException("maximum challenge maturity reached"); } byte[] challenge = authenticationChallenge.getChallenge(); return challenge; }