title: Best way to compare given date with current date without time part in a given time zone
body: <p>My requirement is to compare a given date in a particular format in a given timezone to the current date in the same time zone.
  Also while comparing I have to ignore the timezone.
  And the comparison result should be:
  0 or 1 or -1</p>
  <p>One way I have tried is</p>
  <ol>
  <li>Set the required timezone</li>
  <li>Get the current date using &quot;new Date()&quot; format it using &quot;yyyy-MM-dd&quot; and then parse it again to get the date object</li>
  <li>Use the same formatter for supplied date string to be compared</li>
  <li>Then compare both dates using compareTo which gives the desired result</li>
  </ol>
  <pre class="lang-java prettyprint-override"><code>public void compareDate(){
  
      TimeZone.setDefault(TimeZone.getTimeZone(&quot;America/New_York&quot;));
      SimpleDateFormat dateFormatter = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);
      Date todayDate = dateFormatter.parse(dateFormatter.format(new Date()));
      Date date = dateFormatter.parse(&quot;2021-02-28&quot;);
      System.out.println(todayDate.compareTo(date));
  
  }
  </code></pre>
  <p>But the above looks inefficient to me.</p>
  <p>Other way could be to get both the dates like below and then compare?</p>
  <pre><code>public static Date getDateWithoutTimeUsingCalendar() {
      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.HOUR_OF_DAY, 0);
      calendar.set(Calendar.MINUTE, 0);
      calendar.set(Calendar.SECOND, 0);
      calendar.set(Calendar.MILLISECOND, 0);
  
      return calendar.getTime();
  }
  </code></pre>
  <p>Can someone please suggest a better alternative?</p>
  <p>Just one thing, timezone and comparing without time has to be there.</p>