List of usage examples for java.util Date getTime
public long getTime()
From source file:Main.java
public static int daysBetween(Date d1, Date d2) { return (int) ((d2.getTime() - d1.getTime()) / DateUtils.DAY_IN_MILLIS); }
From source file:Main.java
public static int hoursBetween(Date d1, Date d2) { return (int) ((d2.getTime() - d1.getTime()) / DateUtils.MINUTE_IN_MILLIS); }
From source file:Main.java
public static int minuteBetween(Date d1, Date d2) { return (int) ((d2.getTime() - d1.getTime()) / DateUtils.SECOND_IN_MILLIS); }
From source file:Main.java
public static long ISOtoEpoch(String time) { try {//from w w w .j av a 2 s.com Date d = ISO8601DATEFORMAT.parse(time); return d.getTime(); } catch (ParseException e) { Log.e("Error", e.getLocalizedMessage()); return -2; } }
From source file:Main.java
public static int timeCompare(String str1, String str2) { try {//from w ww . j a v a 2 s .c o m SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date begin = dfs.parse(str1); java.util.Date end = dfs.parse(str2); long between = end.getTime() - begin.getTime(); if (between > 0) { return 1; } else if (between == 0) { return 0; } else { return -1; } } catch (Exception e) { return 1; } }
From source file:com.architexa.rse.DateUtil.java
public static String getGapInHoursAndDays(Date futureEvent) { long timeToEvent = futureEvent.getTime() - now().getTime(); int hoursToEvent = (int) (timeToEvent / 1000 / 60 / 60); int daysToExpire = hoursToEvent / 24; String retVal = daysToExpire + " days"; hoursToEvent -= daysToExpire * 24;/*w w w .j a v a2s. co m*/ if (hoursToEvent > 0) retVal += " " + hoursToEvent + " hours"; return retVal; }
From source file:Main.java
public static long HowLongAgo(String timestamp) { Long tempo;/*from ww w .j a v a 2s . c om*/ try { tempo = Long.parseLong(timestamp); } catch (Exception e) { e.printStackTrace(); return 0; } java.util.Date Now = new java.util.Date(); long diff = (Now.getTime() - tempo); if (diff < 0) return 0; diff /= 1000; return diff; }
From source file:Main.java
public static String getChinaDate(String time) { try {//from ww w . j a v a 2s. c om SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); Date date = format.parse(time); return getChinaDate(date.getTime()); } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static Date getNearestDate(List<Date> dates, Date currentDate) { long minDiff = -1; long currentTime = currentDate.getTime(); Date minDate = null;/* w ww. j av a2 s .c om*/ for (Date date : dates) { long diff = Math.abs(currentTime - date.getTime()); if ((minDiff == -1) || (diff < minDiff)) { minDiff = diff; minDate = date; } } return minDate; }
From source file:Main.java
public static long convertInMillisecond(String dateStrServer) { //String orderDate = null; try {/* w w w . ja v a 2s.c o m*/ Date date = serverSideDateFormator.parse(dateStrServer); return date.getTime(); } catch (Exception e) { e.printStackTrace(); } return 0; }