How to compare a Date date in java?

1

I have the following table, which shows a column called validity

<p:dataTable id="horarios1" rendered="#{ConsultaPersonasUnidadFisicaComponent.muestraHistorial}" var="consultaHorario" style="max-width:3000px;max-height:770px;" value="#{ConsultaPersonasUnidadFisicaComponent.listNivelesPersona2}">
  <p:column headerText="Ubi" style="width: 50px;">
    <h:outputText value="#{consultaHorario.unidadAdministrativa.cveIdUnidadAdmin}" />
  </p:column>

  <p:column headerText="Horario" style="width: 50px;">

  </p:column>

  <p:column headerText="Vigencia">
    <h:outputText value="#{consultaHorario.fecInicioNivel}">
      <f:convertDateTime pattern="dd/MM/yyyy" />
    </h:outputText> -
    <h:outputText value="#{consultaHorario.fecFinNivel}">
      <f:convertDateTime pattern="dd/MM/yyyy" />
    </h:outputText>
  </p:column>

</p:dataTable>

which contains two fields start date and end date, then there are some records that in the field of end date paints the date 3000-12-31 00: 00: 00.0, what I want to do is that when a record brings that date, do not show anything in the date-end field, simply paint a start date 04/12/2016 -

I have the following code

listNivelesPersona2 = nivelesPersonaService.findNivelesPersonaConsultaHorario(cvePersona);

    System.out.println("PRUEBA FECHA FIN \n" +listNivelesPersona2.get(0).getFecFinNivel());

    SimpleDateFormat sdf = new SimpleDateFormat();
    try {
        Date date1 = sdf.parse("3000-12-31");

        if(listNivelesPersona2.get(0).getFecFinNivel().equals(date1)){
            System.out.println("SON IGUALES");
        }


    } catch (ParseException ex) {
        Logger.getLogger(NivelesPersonaComponentImpl.class.getName()).log(Level.SEVERE, null, ex);
    }

I made a variable type date1 and passed that date, then I want to compare the date that comes from my list with date1 and if they are equal, that shows another variable type date but empty and is that I did the test but does nothing, does not enter the system that says they are equal or which is the best way to compare dates, how can I do it?

    
asked by Root93 07.03.2018 в 18:07
source

1 answer

0

If the value retrieved by getFecFinNivel() is also Date()

listNivelesPersona2.get(0).getFecFinNivel().compareTo(date1)

More info on the documentation of Date().compareTo()

    
answered by 07.03.2018 в 18:11