List of usage examples for java.util Date compareTo
public int compareTo(Date anotherDate)
From source file:io.dacopancm.oraclesp.Helper.java
/** * * @param startA/*from ww w.j a v a2 s.c o m*/ * @param endA * @param startB * @param endB * @return return true si las fechas se sobreponen, intersecan */ public static boolean overlapDate(Date startA, Date endA, Date startB, Date endB) { return (startA.compareTo(endB) < 0)// startA menor q endB && (endA.compareTo(startB) > 0); //end A mayor q startB }
From source file:Main.java
public static int compareDates(String dateTime1, String dateTime2, String format) { // 0 is equal, < 0 if date1 is less than date2 try {/*from ww w .j av a 2 s . com*/ SimpleDateFormat df = new SimpleDateFormat(format); Date date1 = df.parse(dateTime1); Date date2 = df.parse(dateTime2); return date1.compareTo(date2); } catch (ParseException e) { e.printStackTrace(); } return 0; }
From source file:com.ocpsoft.socialpm.util.Dates.java
public static boolean isInRange(final Date start, final Date end, final Date date) { if ((date.compareTo(start) >= 0) && (date.compareTo(end) <= 0)) { return true; }/*from w w w . j ava 2s . com*/ return false; }
From source file:com.common.server.AppLicenceUtil.java
public static void logonVertify() throws Exception { Map map = getLicence();/* ww w. j a v a 2s. c om*/ String expire = (String) map.get("expireDate"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); if (expire == null) { return; } Date expireDate = null; try { expireDate = format.parse(expire); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } Date currentDate = new Date(); if (currentDate.compareTo(expireDate) >= 0) { log.info(":expire=" + expire + " currentDate=" + format.format(currentDate)); } log.info(":expire=" + expire + " currentDate=" + format.format(currentDate)); }
From source file:com.ocpsoft.socialpm.util.Dates.java
public static boolean isDateInPast(final Date pastDate) { Date today = new Date(); return !isSameDay(today, pastDate) && (today.compareTo(pastDate) > 0); }
From source file:com.ocpsoft.socialpm.util.Dates.java
public static boolean isDateInFuture(final Date futureDate) { Date today = new Date(); return !isSameDay(today, futureDate) && (today.compareTo(futureDate) < 0); }
From source file:org.lieuofs.extraction.etatpays.ExtractionPays.java
private static List<EtatTerritoirePersistant> filtre(List<EtatTerritoirePersistant> listeOriginal) { List<EtatTerritoirePersistant> listeFiltree = new ArrayList<EtatTerritoirePersistant>(); for (EtatTerritoirePersistant etatTerritoire : listeOriginal) { // On slectionne tous les tats territoire reconnu il ya moins de 2 ans Calendar cal = Calendar.getInstance(); cal.roll(Calendar.YEAR, -5); Date ilYa5an = cal.getTime(); Date dateReconnaissance = etatTerritoire.getDateReconnaissance(); if (null != dateReconnaissance && dateReconnaissance.compareTo(ilYa5an) > 0) { listeFiltree.add(etatTerritoire); }/*from ww w . j a v a 2 s . c o m*/ } return listeFiltree; }
From source file:com.axelor.apps.tool.net.MyFtp.java
public static void getDataFiles(String server, String username, String password, String folder, String destinationFolder, Calendar start, Calendar end) { try {/*from w ww . java 2 s . co m*/ // Connect and logon to FTP Server FTPClient ftp = new FTPClient(); ftp.connect(server); ftp.login(username, password); // List the files in the directory ftp.changeWorkingDirectory(folder); FTPFile[] files = ftp.listFiles(); for (int i = 0; i < files.length; i++) { Date fileDate = files[i].getTimestamp().getTime(); if (fileDate.compareTo(start.getTime()) >= 0 && fileDate.compareTo(end.getTime()) <= 0) { // Download a file from the FTP Server File file = new File(destinationFolder + File.separator + files[i].getName()); FileOutputStream fos = new FileOutputStream(file); ftp.retrieveFile(files[i].getName(), fos); fos.close(); file.setLastModified(fileDate.getTime()); } } // Logout from the FTP Server and disconnect ftp.logout(); ftp.disconnect(); } catch (Exception e) { LOG.error(e.getMessage()); } }
From source file:Main.java
public static int compareDateStr(String dateStr1, String dateStr2, String format) { int result = 0; if (TextUtils.isEmpty(dateStr1) && !TextUtils.isEmpty(dateStr2)) { return 1; }/*from w ww . j a v a 2 s . co m*/ if (!TextUtils.isEmpty(dateStr1) && TextUtils.isEmpty(dateStr2)) { return -1; } if ((TextUtils.isEmpty(dateStr1) && TextUtils.isEmpty(dateStr2)) || TextUtils.isEmpty(format)) { return 0; } Date d1 = getDate(dateStr1, format); Date d2 = getDate(dateStr2, format); if (d1 == null || d2 == null) { return result; } result = d2.compareTo(d1); return result; }
From source file:Main.java
public static int compareDate(String strDate1, String strDate2) { int value = 0; Date d1 = stringToDate(strDate1, "yyyy-MM-dd HH:mm:ss"); Date d2 = stringToDate(strDate2, "yyyy-MM-dd HH:mm:ss"); if (d1 == null || d2 == null) { return value; }/*from w w w . j a v a2 s .com*/ value = d2.compareTo(d1); return value; }