Here you can find the source of compareFileDates(final Date date1, final Date date2)
Parameter | Description |
---|---|
date1 | first file modification date |
date2 | second file modification date |
true
if files modification dates are equal ignoring milliseconds
public static boolean compareFileDates(final Date date1, final Date date2)
//package com.java2s; /***************************************************************************** * Java Plug-in Framework (JPF)// w ww .j a v a 2s .co m * Copyright (C) 2004-2006 Dmitry Olshansky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ import java.util.Calendar; import java.util.Date; import java.util.Locale; public class Main { /** * For some reason modification milliseconds for some files are unstable, * use this function to compare file dates ignoring milliseconds. * @param date1 first file modification date * @param date2 second file modification date * @return <code>true</code> if files modification dates are equal ignoring * milliseconds */ public static boolean compareFileDates(final Date date1, final Date date2) { if ((date1 == null) || (date2 == null)) { return false; } Calendar cldr = Calendar.getInstance(Locale.ENGLISH); cldr.setTime(date1); cldr.set(Calendar.MILLISECOND, 0); long dt1 = cldr.getTimeInMillis(); cldr.setTime(date2); cldr.set(Calendar.MILLISECOND, 0); long dt2 = cldr.getTimeInMillis(); return dt1 == dt2; } }