Date fechaHoy = new Date();
if (fechaHoy.after(fechaIni) && fechaHoy.before(fechaFin) ||
isSameDay(fechaHoy, fechaIni) || isSameDay(fechaHoy, fechaFin)) {
return true;
}
private static boolean esMismoDia(Date fecha1, Date fecha2) {
if (fecha1 == null || fecha2 == null) {
throw new IllegalArgumentException("Las fechas no pueden ser null");
}
Calendar cal1 = Calendar.getInstance();
cal1.setTime(fecha1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(fecha2);
return isSameDay(cal1, cal2);
}
private static boolean esMismoDia(Calendar cal1, Calendar cal2) {
if (cal1 == null || cal2 == null) {
throw new IllegalArgumentException("Las fechas no pueden ser null");
}
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
}
Este blog pretende recopilar ideas que me van surgiendo con los días y compartirlas con los demás.
17 mayo 2012
Comparar Fechas en Java
Como comparar fechas en java desde una fecha inicial, una final y la actual:
Etiquetas:
fechas,
java,
snippet
Ubicación:
A Coruña, España
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario