List of usage examples for java.util Date getTime
public long getTime()
From source file:Main.java
/** * Get relativy days base on today, will return negative and positive * values.//w ww. j a v a2 s. c o m * * @param d * @return */ public static long getRelativeDays(Date d) { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); long curMilli = c.getTimeInMillis(); c.setTimeInMillis(d.getTime()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); long dMilli = c.getTimeInMillis(); return (dMilli - curMilli) / (1 * 24 * 3600 * 1000); }
From source file:com.coinblesk.server.utilTest.ServerCalls.java
public static SignTO signServerCallInput(Transaction tx, ECKey client, Date date) throws Exception { SignTO prepareHalfSignTO = new SignTO().transaction(tx.unsafeBitcoinSerialize()) .publicKey(client.getPubKey()).currentDate(date.getTime()); SerializeUtils.signJSON(prepareHalfSignTO, client); return prepareHalfSignTO; }
From source file:Main.java
/** * Builds an Intent to add a new event to the calendar. * * @param title The title of the event.//from ww w . j ava 2 s .com * @param start The start date and time. * @param end The end date and time. * @param where Where the event is held (e.g.: an address). */ public static Intent getAddEventIntent(final String title, final Date start, final Date end, final String where) { Intent intent = new Intent(Intent.ACTION_INSERT); intent.setData(CalendarContract.Events.CONTENT_URI); intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start.getTime()); intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end.getTime()); intent.putExtra(CalendarContract.Events.TITLE, title); if (where != null) { intent.putExtra(CalendarContract.Events.EVENT_LOCATION, where); } return intent; }
From source file:com.bloatit.web.HtmlTools.java
/** * <p>//w w w .ja v a 2s . c o m * Clean and formats the date * </p> * <p> * Date is rendered : * <li> <code>now</code> if it's been posted less than one second ago</li> * <li> <code>x seconds ago</code> if it's been posted less than 1 minute ago * </li> * <li> <code>Jan 12, 1952</code> otherwise</li> * </p> * <p> * Note, this method will completly ignore <i>any</i> time information, and * display only the date. To display time, use * {@link #formatDateTime(DateLocale)}. * </p> * * @param date the localized date to render * @return the rendered date */ public static String formatDate(final DateLocale date) { final Date currentDate = new Date(); final long diff = currentDate.getTime() - date.getJavaDate().getTime(); if (diff < SECOND) { return Context.tr("now"); } else if (diff < MINUTE) { return Context.trn("{0} second ago", "{0} seconds ago", Long.valueOf(diff / SECOND), Long.valueOf(diff / SECOND)); } else if (diff < HOUR) { return Context.trn("{0} minute ago", "{0} minutes ago", Long.valueOf(diff / MINUTE), Long.valueOf(diff / MINUTE)); } else if (diff < DAY) { return Context.trn("{0} hour ago", "{0} hours ago", Long.valueOf(diff / HOUR), Long.valueOf(diff / HOUR)); } return date.toString(FormatStyle.MEDIUM); }
From source file:com.espertech.esper.client.util.DateTime.java
/** * Returns a long-millisecond value from a given string using the provided format. * @param datestring to parse/* w w w . j a va 2 s .c o m*/ * @param format to use for parsing * @return long msec */ public static Long toMillisec(String datestring, String format) { Date date = parse(datestring, format); if (date == null) { return null; } return date.getTime(); }
From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2DeserializerTests.java
private static void assertTokenEquals(OAuth2AccessToken expected, OAuth2AccessToken actual) { assertEquals(expected.getTokenType(), actual.getTokenType()); assertEquals(expected.getValue(), actual.getValue()); OAuth2RefreshToken expectedRefreshToken = expected.getRefreshToken(); if (expectedRefreshToken == null) { assertNull(actual.getRefreshToken()); } else {/*from w w w.ja v a2 s. com*/ assertEquals(expectedRefreshToken.getValue(), actual.getRefreshToken().getValue()); } assertEquals(expected.getScope(), actual.getScope()); Date expectedExpiration = expected.getExpiration(); if (expectedExpiration == null) { assertNull(actual.getExpiration()); } else { assertEquals(expectedExpiration.getTime(), actual.getExpiration().getTime()); } assertEquals(expected.getAdditionalInformation(), actual.getAdditionalInformation()); }
From source file:com.amazonaws.util.JodaTime.java
private static boolean checkTT0031561767() throws ParseException { String input = "Fri, 16 May 2014 23:56:46 GMT"; Date date = new Date(DateUtils.rfc822DateFormat.parseMillis(input)); return input.equals(DateUtils.rfc822DateFormat.print(date.getTime())); }
From source file:com.haulmont.timesheets.global.DateTimeUtils.java
private static Set<String> holidayAsSeparateStrings(Holiday holiday, Date startDate, Date endDate, String format) {//from ww w. j a v a2s. c om Date start; Date end; if (holiday.getStartDate().getTime() >= startDate.getTime()) { start = holiday.getStartDate(); } else { start = startDate; } if (holiday.getEndDate().getTime() <= endDate.getTime()) { end = holiday.getEndDate(); } else { end = endDate; } if (start.equals(startDate) && end.equals(endDate)) { return Collections.emptySet(); } else { Set<String> stringDates = new HashSet<>(); DateFormat formatter = new SimpleDateFormat(format); while (start.getTime() <= end.getTime()) { stringDates.add(formatter.format(start)); start = DateUtils.addDays(start, 1); } return stringDates; } }
From source file:index.IndexUtils.java
@SuppressWarnings("deprecation") public static List queryByOneKey(IndexSearcher indexSearcher, String field, String key) throws ClassNotFoundException, IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, NoSuchMethodException { try {/*from ww w . ja v a 2s .c o m*/ Date date1 = new Date(); QueryParser queryParser = new QueryParser(field, new StandardAnalyzer()); Query query = queryParser.parse(key); Hits hits = indexSearcher.search(query); Date date2 = new Date(); System.out.println("" + (date2.getTime() - date1.getTime()) + "ms"); List list = new ArrayList(); for (int i = 0; i < hits.length(); i++) { list.add(getIndexResult(hits.doc(i), "index.IndexResult")); } return list; } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static float getTimeDiff(String start, String end) { java.text.DateFormat df = new java.text.SimpleDateFormat("HH:mm:ss"); java.util.Date date1 = null, date2 = null; try {// www . ja va 2s .co m date1 = df.parse(start); date2 = df.parse(end); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return (float) ((date2.getTime() - date1.getTime())); }