List of usage examples for java.util Date getTime
public long getTime()
From source file:Main.java
/** * Converts a <code>java.util.Date</code> instance to a * <code>javax.xml.datatype.XMLGregorianCalendar</code> instance. * * @param date the <code>java.util.Date</code> instance to convert * * @return the converted <code>javax.xml.datatype.XMLGregorianCalendar</code> instance *//* w w w.j ava2s . c o m*/ public static XMLGregorianCalendar asXMLGregorianCalendar(java.util.Date date) { if (date == null) { return null; } else { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(date.getTime()); return datatypeFactory.newXMLGregorianCalendar(calendar); } }
From source file:com.qdum.llhb.common.utils.DateUtils.java
/** * /*from w w w . j a va 2 s .c o m*/ * * @param date1 * @param date2 * @return */ public static long pastMinutes(Date date1, Date date2) { long t = date1.getTime() - date2.getTime(); return t / (60 * 1000); }
From source file:DateUtility.java
/** * This will retun the first millisecond of the month * that contains the timestamp provided/*from w w w. j a va 2 s . c om*/ * @param timestamp * @return long */ static public long getFirstMilliOfMonth(long timestamp, TimeZone tz) { GregorianCalendar cal = new GregorianCalendar(); cal.setTimeZone(tz); cal.setTime(new Date(timestamp)); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); return date.getTime(); }
From source file:com.pursuer.reader.easyrss.Utils.java
public static String timestampToTimeAgo(final Context context, final long timestamp) { final Date date = timestampToDate(timestamp); final long delta = new Date().getTime() - date.getTime(); if (delta < 60 * 60 * 1000) { return context.getString(R.string.TxtLessThanOneHourAgo); } else if (delta < 40 * 60 * 60 * 1000) { return String.valueOf(delta / (60 * 60 * 1000) + 1) + " " + context.getString(R.string.TxtHoursAgo); } else {//from w w w . ja v a2s . com return String.valueOf(delta / (24 * 60 * 60 * 1000) + 1) + " " + context.getString(R.string.TxtDaysAgo); } }
From source file:com.bjond.utilities.DateTimeUtils.java
/** * return true if firstDate greater than or equal to secondDate * * @param firstDate Valid non-null java.util.Date object * @param secondDate Valid non-null java.util.Date object * @return New date. Original is not altered. *//* w w w . ja v a 2 s . co m*/ public static boolean isEqualToOrGreaterThan(final Date firstDate, final Date secondDate) { return (firstDate != null && secondDate != null && firstDate.getTime() >= secondDate.getTime()); }
From source file:com.b5m.user.frame.util.DateUtils.java
/** * ?/*from www .j av a 2 s . co m*/ * @param deadline ,?yyyyMMddHHmmss * @return */ public static String getRemainingTime(String endDate) { String rtn = ""; if (StringUtils.isBlank(endDate)) return rtn; SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");//ComConstants.SDF_YYYYMMDDHHMMSS;//??? try { Date deadline = sdf.parse(endDate); long remaining = deadline.getTime() - System.currentTimeMillis(); //long remaining=lngDeadline-System.currentTimeMillis(); if (remaining > 0) { //int ms = (int) (remaining % 1000); remaining /= 1000; //int sc = (int) (remaining % 60); remaining /= 60; int mn = (int) (remaining % 60); remaining /= 60; int hr = (int) (remaining % 24); long dy = (int) remaining / 24; rtn = dy + "" + hr + "?" + mn + "";//+ sc + ""; } else { rtn = ""; } } catch (ParseException e) { } return rtn; }
From source file:com.foglyn.fogbugz.Utils.java
static Date copyOf(Date date) { if (date == null) { return null; }/* ww w. ja v a 2 s. c om*/ return new Date(date.getTime()); }
From source file:Main.java
/** * Checks if two date objects represent the same instant in time. * * This method compares the long millisecond time of the two objects. * /* www . jav a2 s . co m*/ * @param date1 the first date, not altered, not null * @param date2 the second date, not altered, not null * @return true if they represent the same millisecond instant * @throws IllegalArgumentException if either date is <code>null</code> * @since 2.1 */ public static boolean isSameInstant(Date date1, Date date2) { if (date1 == null || date2 == null) { throw new IllegalArgumentException("The date must not be null"); } return date1.getTime() == date2.getTime(); }
From source file:Main.java
@SuppressLint("SimpleDateFormat") public static String getTimes(String times) { String time = ""; try {/*from w w w. jav a2 s . c om*/ Date epoch = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse(times.toString().substring(8, 10) + "/" + times.toString().substring(5, 7) + "/" + times.toString().substring(0, 4) + " 01:00:00"); time = epoch.getTime() / 1000 + ""; } catch (ParseException e) { e.printStackTrace(); } return time; }
From source file:com.vmware.identity.util.TimePeriod.java
/** * @param period// w w w .j a va 2 s .c o m * of time for expansion. Cannot be null. * @param tolerance * in milliseconds. Non-negative. * @return left and right expanded interval with given time. If interval is * opened expansion is applied only on closed side of interval. */ public static TimePeriod expand(TimePeriod period, long tolerance) { Validate.notNull(period); Validate.isTrue(tolerance >= 0); if (tolerance == 0) { return period; } Date startTime = period.getStartTime(); startTime = (startTime != null) ? new Date(startTime.getTime() - tolerance) : null; Date endTime = period.getEndTime(); endTime = (endTime != null) ? new Date(endTime.getTime() + tolerance) : null; return new TimePeriod(startTime, endTime); }